怎样实现unity3d 物体隐藏,我想随着unity的学习我们大家已经对unity3d 物体隐藏不是那么陌生了,今天我们再来学习一下,就当成复习,对不熟悉的朋友也是帮助。
1.using UnityEngine;
2.using System.Collections;
3.public class test : MonoBehaviour {
4. public Transform target;
5. void Start(){
6. }
7.
8. void OnGUI(){
9. //renderer control
12. foreach(MeshRenderer m in marr){
13. m.enabled = true;
14. }
15. }
16. if(GUILayout.Button("hide")){
17. MeshRenderer[] marr = target.GetComponentsInChildren<MeshRenderer>(true);
18. foreach(MeshRenderer m in marr){
19. m.enabled = false;
20. }
21. }
22. }
23.}
1.using UnityEngine;
2.using System.Collections;
3.public class test : MonoBehaviour {
4. public Transform target;
5. void Start(){
6. }
7.
8. void OnGUI(){
9. //renderer control
10.if(GUILayout.Button("display")){
11. MeshRenderer[] marr = target.GetComponentsInChildren<MeshRenderer>(true);12. foreach(MeshRenderer m in marr){
13. m.enabled = true;
14. }
15. }
16. if(GUILayout.Button("hide")){
17. MeshRenderer[] marr = target.GetComponentsInChildren<MeshRenderer>(true);
18. foreach(MeshRenderer m in marr){
19. m.enabled = false;
20. }
21. }
22. }
23.}