Unity3d 5 WavePro动态MeshCollider [英] Unity3d 5 WavePro Dynamic MeshCollider

查看:54
本文介绍了Unity3d 5 WavePro动态MeshCollider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im使用Water4Advance在Unity3d 5.0中模拟海浪. 我在运行系统中使用Gerstner Displace取代了飞机. 我看到了网格如何变形,并向其中添加了MeshCollider,并且我想在运行时刷新此collider网格. 我正在使用以下脚本在Unity 4.6上进行此操作:

Im using Water4Advance to simulate an ocean waves in Unity3d 5.0. I have my plane displaced in Runtime with Gerstner Displace. I see how the mesh is deformed and i add a MeshCollider to it and i like to refresh this collider mesh in runtime. I was working this on Unity 4.6 with this script:

MeshCollider collider = GetComponent<MeshCollider>();
Mesh mesh = GetComponent<MeshFilter>().mesh;
collider.sharedMesh = null;
collider.sharedMesh = mesh;

但是现在我只得到了平面的原始平面预制件.

But now i only got the flat original plane prefab.

如何用置换的网格更新此MeshCollider?

How can i update this MeshCollider with the displaced mesh?

推荐答案

尝试一下:

Mesh myMesh = this.GetComponent<MeshFilter>().mesh;
DestroyImmediate(this.GetComponent<MeshCollider>());
var collider = this.AddComponent<MeshCollider>();
collider.sharedMesh = myMesh;

从这里:

http://answers.unity3d. com/questions/446910/changing-mesh-collider-at-run-time.html

这篇关于Unity3d 5 WavePro动态MeshCollider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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