用C# Transform实现物体隐藏的过程是怎样的?现在我们就通过相关代码完成这一过程。
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;
}
}
}
}
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;
}
}
}
}