简体   繁体   English

是否可以在不将其添加到GameObject的情况下创建Unity组件?

[英]Is it possible to create a Unity Component without adding it to a GameObject?

So I'm trying to create a Joint component separately before I add it as a component onto a GameObject. 因此,我尝试单独创建一个Joint组件,然后再将其作为一个组件添加到GameObject上。 Is this possible/recommended? 这可能/建议吗? If it's possible but not recommended, why? 如果可能但不建议这样做,为什么呢?

The way Unity is designed, every Component must be attached to a GameObject. Unity的设计方式必须将每个组件都附加到GameObject。

However, you might be interested in designs such as the singleton pattern , where your script automatically creates exactly one copy of a Component, which can potentially be shared across all scripts in all of your scenes. 但是,您可能对诸如singleton pattern之类的设计感兴趣,在该设计中,脚本会自动创建一个组件的一个副本,该副本可以在您所有场景中的所有脚本之间共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM