小编yoc*_* le的帖子

如何检查GameObject是否包含MeshRenderer但不包含任何对撞机,然后向其添加对撞机?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AddColliders : MonoBehaviour
{
    public List<GameObject> objectsToAddCollider = new List<GameObject>();

    // Start is called before the first frame update
    void Start()
    {
        AddDescendantsWithTag(transform, objectsToAddCollider);
    }

    // Update is called once per frame
    void Update()
    {

    }

    private void AddDescendantsWithTag(Transform parent, List<GameObject> list)
    {
        foreach (Transform child in parent)
        {
            if (child.gameObject.GetComponent<MeshRenderer>() != null
                && child.gameObject.GetComponent<)
            {
                list.Add(child.gameObject);
            }
            AddDescendantsWithTag(child, list);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在这一行中,我正在检查是否有附加到游戏对象的网格渲染器,但如何检查它是否未附加任何碰撞类型?然后如何向其添加网格碰撞器?

这是我到目前为止尝试过的:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

3
推荐指数
1
解决办法
57
查看次数

标签 统计

c# ×1

unity-game-engine ×1