unity3d给子物体添加MeshCollider

2023-08-24 13:43:42 浏览数 (2)

代码语言:javascript复制
using UnityEngine;
using System.Collections;

public class AutoAddCollision : MonoBehaviour {

	// Use this for initialization
	void Start () {
        ModelAddMeshCollider();

    }
	
    void ModelAddMeshCollider()
    {
        foreach (var render in transform.GetComponentsInChildren<MeshRenderer>())
        {
            render.gameObject.AddComponent<MeshCollider>();
        }
    }
}

0 人点赞