Babybus-u3d技术交流-Dynamic RayCast System 动态网格碰撞体
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(SkinnedMeshRenderer), typeof(MeshCollider))]
public class DynamicMeshCollider : MonoBehaviour
{
private SkinnedMeshRenderer skinnedMeshRenderer;
private Mesh mesh;
// Use this for initialization
void Awake()
{
skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
mesh = Instantiate(skinnedMeshRenderer.sharedMesh) as Mesh;
GetComponent<MeshCollider>().sharedMesh = mesh;
}
// Update is called once per frame
void Update()
{
skinnedMeshRenderer.BakeMesh(mesh);
}
}
比assetstore上的这玩意好用
[https://www.assetstore.unity3d.com/en/#!/content/20844
使用须知:
放在SkinnedMeshRenderer组件旁边即可。
Animator组件需要enable状态,上面也要有对应的动画控制器(Animator Controller)。