如何在 Unity3D 中使用 GameObject.Find(" ") 查找非活动对象? [英] How to find inactive objects using GameObject.Find(" ") in Unity3D?

查看:32
本文介绍了如何在 Unity3D 中使用 GameObject.Find(" ") 查找非活动对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 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) 调用(尽管应该非常小心地使用).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆