在unity中利用公开变量引用物体和组件(有手就会)

编程入门 行业动态 更新时间:2024-10-19 13:33:28

在unity中利用公开变量引用物体和组件(有手<a href=https://www.elefans.com/category/jswz/34/1758032.html style=就会)"/>

在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中利用公开变量引用物体和组件(有手就会)

本文发布于:2023-12-05 21:20:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1665338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:就会   变量   物体   组件   unity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!