cneicy / cneicy.github.io

Blog
0 stars 0 forks source link

crash-2024-03-21_17.11.00-fml #9

Open utterances-bot opened 1 week ago

utterances-bot commented 1 week ago

从MonoBehavior不允许使用new了解Unity的继承关系

MonoBehavior下gameObject不能为static则导致抽象工厂继承自MonoBehavior的话不被允许使用new关键字传递对象。 浅显一点的原因是MonoBehavior继承自Component,所以传递的也被规定为Component。 但是Unity给我们留下了口子。 感谢CSDN大佬( https://blog.csdn.net/woodengm/article/detai

https://cneicy.github.io/crash-2024-03-21_17.11.00-fml.htm

cneicy commented 1 week ago

实际上实例化物体后进行添加组件的方式更好,因为ScriptableObject应该不是干这个用的。