Unity3D:GetChild()vs FindGameObjectWithTag()vs附加预制件



我使用的是GetChild(),它是我排列的特定数字。但是当子对象开始变乱时,我无法使用GetChild()。

现在我有三个选择。

1. Try to sort the child objects overtime they get shuffled. I need to
use this option when GetChild() is must faster compared to the
below.
2. FindGameObjectWithTag(): I read, Finding game objects with tags executes much faster than finding with names.
3. I have a total to 81 characters in the scene. Is it wise to attach all the 81 to the script upfront and access from that game
objects array?

谢谢。

如果您从单点实例化所有81个字符,我认为将它们存储在集合中以进行进一步的操作或将操作委托给不同的对象进行处理是完全有效的。

确实,使用tag搜索是最快的搜索方式之一,但当您检查name而不是.GetComponent<T>()时,大约是在同一时间找到您要查找的内容。从编程的角度来看,我宁愿使用集合和引用,而不是游戏对象名称,因为名称很容易因任何特定原因而更改(例如,有人根据角色类型更改游戏对象的名称)。此外,请注意,游戏对象名称可以重复

注意:您指的是附加的预制件,但您实际上应该存储预制件实例化产生的游戏对象。

最新更新