如何在Unity3D中使用GameObject.Find(“")查找不活动的对象? [英] How to find inactive objects using GameObject.Find(" ") in Unity3D?
问题描述
我需要使用C#在Unity3D中找到不活动的对象.
I needed to find inactive objects in Unity3D using C#.
我有64个对象,每当我单击一个按钮时,它就会在运行时激活/禁用相应按钮的对象.我现在如何找到不活动的对象?
I have 64 objects, and whenever I click a button then it activates / inactivates objects for the corresponding button at runtime. How can I find inactive objects at this time?
推荐答案
使用GameObject.Find(...)
绝不会返回任何非活动对象. 根据文档说明:
Well, using GameObject.Find(...)
will never return any inactive objects. As the documentation states:
此函数仅返回活动的游戏对象.
This function only returns active gameobjects.
即使可以,您也希望将这些昂贵的电话费用降至最低.
Even if you could, you'd want to keep these costly calls to a minimum.
查找无效的游戏对象有技巧",例如使用 Resources.FindObjectsOfTypeAll(Type type)
致电(尽管应格外小心).
There are "tricks" to finding inactive GameObjects, such as using a Resources.FindObjectsOfTypeAll(Type type)
call (though that should be used with extreme caution).
但是最好的办法是编写自己的管理代码.这可以是一个简单的类,其中包含您可能希望在某个时候找到和使用的对象列表.您可以在第一次加载时将对象放入其中.或者,在活动或不活动时添加/删除它们.无论您的特定情况需要什么.
But your best bet is writing your own management code. This can be a simple class holding a list of objects that you might want to find and use at some point. You can put your object into it on first load. Or perhaps add/remove them on becoming active or inactive. Whatever your particular scenario needs.
这篇关于如何在Unity3D中使用GameObject.Find(“")查找不活动的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!