如何将自定义类添加为unity的GameObject的组件?
因此,我有一个预先实例化的预制措施,该预制是我创建的那个预制,并在小时候添加了一个带有组件图像的游戏对象。现在,如何将自定义类数据作为组件添加到预制的新创建的孩子中?
So I have a prefab which is Instantiated in run time, to that prefab I create and add another game object with components Image as a child. Now here how can I add a custom class data as component to the newly created child of prefab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了能够将您的自定义脚本添加到场景上的游戏对象中,必须从
Monobehaviour
继承此自定义脚本。之后,您可以在Inspector中添加类“ Do Game对象”(通过单击添加组件
按钮,请参见下面的图像),也可以通过调用To be able to add your custom script to the game object on the scene, this custom script must be inherited from
MonoBehaviour
. After that, you can add your class do game object in the inspector (by clickingAdd Component
button, see image below) or from code by calling