如何获取component
发布网友
发布时间:2022-05-12 07:43
我来回答
共1个回答
热心网友
时间:2024-02-19 21:48
function GetComponent (type : string) : Component
Description描述
Returns the component with name type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回名字类型组件,如果没有则为null。
It is better to use GetComponent with a Type instead of a string for performance reasons. Sometimes you might not be able to get to the type however, for example when trying to access a C# script from Javascript. In that case you can simply access the component by name instead of type. Example:
由于性能原因,最好使用Type的GetComponent,而不是用字符串。不过有时你可能无法得到Type,例如当你从Javascript访问C#脚本时,这个时候你可以简单通过名字而不是type来访问组件。