就会)"/>
在unity中利用公开变量引用物体和组件(有手就会)
在任意的脚本组件中,添加一个公开的 GameObject 类型的变量
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class test1 : MonoBehaviour
{public GameObject other;// Start is called before the first frame updatevoid Start(){if(other != null){Debug.Log("other物体名称是:" + other.name);}else{Debug.Log("未指定other物体");}}}
然后再查看 Inspector (检查器)窗口,发现test1的脚本属性会多一个该变量的编辑框,直接把想要的组件拖进去就可以实现绑定了!
也可以点击右边进行物体的选择!
更多推荐
在unity中利用公开变量引用物体和组件(有手就会)
发布评论