【发布时间】:2020-09-03 00:50:18
【问题描述】:
我正在使用它在 GameObject 中查找一些脚本:
GameObject.Find("GameView").GetComponent<SomeClass>();
我是 Unity 新手,想看看以下是否可行:
SomeClass View1;
SomeClass View2;
View2 = GameObject.Find("GameView").GetComponent<View1.GetType()>();
当然会引发错误。但是是否可以为GetComponent动态分配类定义?
【问题讨论】:
-
@Pluto 不,它不会。
public bool TryGetComponent(Type type, out Component component);会。泛型类型参数总是必须是编译时常量
标签: unity3d