首页 > 其他分享 >unity GetComponent使用

unity GetComponent使用

时间:2023-03-15 23:12:28浏览次数:25  
标签:脚本 绑定 对象 模型 NewGame unity GetComponent 使用

GetComponent得到单独一个对象或属性

可用于获取:模型对象,对象的属性,对象悬挂脚本

//获取模型对象
脚本名(ScriptName) 接收对象(Model) = GetComponent<脚本名(ScriptName)>();//通过模型绑定的脚本来获取模型对象, 注意:如果多个模型上绑定同一个脚本,只会获取到最后绑定脚本的模型对象
//获取对象的属性
GameObject NewGame;//创建一个对象并为对象赋值
Button button= NewGame.GetComponent<Button>();//得到NewGame绑定的button属性
//对象悬挂脚本
GameObject NewGame;//创建一个对象并为对象赋值
脚本名(ScriptName) 接收对象(Model) = NewGame.GetComponent<脚本名(ScriptName)>();//得到NewGame绑定的脚本

标签:脚本,绑定,对象,模型,NewGame,unity,GetComponent,使用
From: https://www.cnblogs.com/rjh-blog/p/17220570.html

相关文章