简体   繁体   English

如何获得添加到 Hierarchy 中所有模型和对象的所有 Mesh Colliders 组件?

[英]How can i get all the Mesh Colliders Components i added to all models and objects in Hierarchy?

To add them all i marked and selected in the Hierarchy all the models and objects and then in the meny i did Component > Physics > Mesh Collider为了添加它们,我在层次结构中标记并选择了所有模型和对象,然后在菜单中我做了组件>物理>网格碰撞器

But now i want to delete/remove all the Mesh Colliders i added.但现在我想删除/删除我添加的所有网格碰撞器。 But i want to do it with a script.但我想用脚本来做。

What i want is to list in array or List all the Mesh Colliders and then to decide what to do with each one of them if to delete rename or anything else.我想要的是在数组中列出或列出所有网格碰撞器,然后决定如何处理它们中的每一个,如果删除重命名或其他任何东西。

GameObject.FindObjectsOfType(typeof(MonoBehaviour)); //returns Object[]
GameObject.FindGameObjectsWithTag("Untagged");  //returns GameObject[]

This will return all the gameobjects but it's not what i need.这将返回所有游戏对象,但这不是我需要的。

With FindObjectsOfType :使用FindObjectsOfType

To find with MeshColliders with FindObjectsOfType , provide MeshCollider as the type.要使用 FindObjectsOfType 使用FindObjectsOfType ,请提供MeshCollider作为类型。 Convert it into MeshCollider array.将其转换为MeshCollider数组。

    MeshCollider[] allMeshes = GameObject.FindObjectsOfType(typeof(MeshCollider)) as MeshCollider[];
    for (int i = 0; i < allMeshes.Length; i++)
    {
        allMeshes[i].enabled = false; //Optional
        Destroy(allMeshes[i]);
    }

With FindGameObjectsWithTag :使用FindGameObjectsWithTag

Find the GameObject that contains the Colliders with their tags.找到包含碰撞器及其标签的游戏​​对象。 Store to GameObject array then use getComponent to get the MeshCollider from them.存储到 GameObject 数组,然后使用getComponent从中获取MeshCollider

    GameObject[] tempObj = GameObject.FindGameObjectsWithTag("Untagged") as GameObject[];
    MeshCollider[] allMeshes = new MeshCollider[tempObj.Length];


    for (int i = 0; i < allMeshes.Length; i++)
    {
        allMeshes[i] = tempObj[i].GetComponent<MeshCollider>();
        if (allMeshes[i] != null)
        {
            allMeshes[i].enabled = false; //Optional
            Destroy(allMeshes[i]);
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让所有游戏对象检查哪些游戏对象有碰撞器,哪些游戏对象根本没有碰撞器? - How can I get all gameobjects to check what gameobjects have colliders and what colliders and what gameobjects dont have colliders at all? 如何让列表中的所有对撞机相互忽略? - How do I get all colliders in a list to ignore each other? 如何在层次结构中找到所有 ui 文本组件,然后禁用/启用它们? - How can I find all the ui text components in the hierarchy and then to disable/enable them? 如何循环遍历层次结构中的所有游戏对象,包括两个场景中的禁用对象所有子对象? - How can I loop over all game objects in hierarchy including disabled objects all children too in both scenes? 如何使用所有组件(脚本,对撞机等)存储GameObjects列表 - How to store a list of GameObjects with all components (scripts, colliders etc) 如何正确制作对象列表的列表(主要),以便将项目添加到列表时,不会将其添加到列表(主要)中的所有列表? - How can I make a List(main) of Lists of Objects correctly so that when an item is added to a list, it is not added to all the lists in the List(main)? 我可以使用LINQ获得某种类型的所有组件吗? - Can I use LINQ to get all components of a certain type? 如何获得com +应用程序的所有com +组件的列表? - How can I get a list of all the com+ components of a com+ application? 如何列出游戏对象上的所有组件,不包括 Transform 以及如何销毁(删除)组件? - How can I list all components on a gameobject exclude the Transform and how can I destroy(delete) the components? 如何在不丢失任何形状的情况下简化基本网格? - How can can I simplify a basic mesh without losing any shape at all?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM