摘要: 1,同一个脚本挂载在不同的对象上 1 public class Lesson1 : MonoBehaviour 2 { 3 // Start is called before the first frame update 4 5 6 //public GameObject Obj1; 7 publi 阅读全文
posted @ 2021-07-25 19:08 青梨 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 1 void Start() 2 { 3 //获取当前对象 4 GameObject l1 = this.gameObject; 5 6 //获取指定对象 7 GameObject l2 = GameObject.Find("ls1"); 8 print(l1); 9 10 } 阅读全文
posted @ 2021-07-25 18:32 青梨 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 1 void Start() 2 { 3 //所有对象挂载了相同的脚本 4 5 Lesson1 t1 = this.GetComponent("Lesson1") as Lesson1; 6 print(t1); 7 8 Lesson1 t2 = this.GetComponent(typeof(L 阅读全文
posted @ 2021-07-25 18:31 青梨 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 1,获取当前挂载的对象名称 void Start() { //获取当前挂载的对象名称 print(gameObject.name); } 2,当前对象失活激活 void Start() { //当前对象失活 this.enabled = false; //当前对象激活 this.enabled = 阅读全文
posted @ 2021-07-25 17:08 青梨 阅读(833) 评论(0) 推荐(0) 编辑