unity代码控制物体不显示也就是隐藏物体,现在就有一段代码控制物体隐藏不显示。
- using UnityEngine;
- using System.Collections;
- public class test : MonoBehaviour
- {
- public Transform target;
- void Start()
- {
- }
- void OnGUI()
- {
- //renderer control
- if(GUILayout.Button("display"))
- {
- MeshRenderer[] marr = target.GetComponentsInChildren<MeshRenderer>(true);
- foreach(MeshRenderer m in marr)
- {
- m.enabled = true;
- }
- }
- if(GUILayout.Button("hide"))
- {
- MeshRenderer[] marr = target.GetComponentsInChildren<MeshRenderer>(true);
- foreach(MeshRenderer m in marr)
- {
- m.enabled = false;
- }
- }
- }
- }