unity提供了多种获取某个对象的方法,

       1. GameObject.Find("name");

       2. GameObject.FindGameObjectWithTag("tag");

      find方法都是全场景寻找,算是unity里最耗事的一种方法,通过tag寻找次之,unity内置了tag系统,应当说是较常见的方法之一,如果需要全场景寻找,FindWithTag会是不错的选择。

      4.transform.GetComponent<T>,transform.GetComponentInChildren<T>,transform.GetComponents<T>

       这是基于当前脚本,通过类型Class来获取某个类,

     5.transform.Find("name");

     也可通过名字获取子对象,

       另外也可选择在实例化对象时保存引用,这是最快的方法。

      

相关文章:

  • 2021-12-11
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-06-22
  • 2021-09-21
相关资源
相似解决方案