【Unity】脚本实现动态模型切割
·
目前做的一个项目中涉及到了模型切割
本项目基于 GitHub上一个开源的模型切割项目ezy-slice为基础开发
这个项目中的效果是在编辑场景中,拖动物体到脚本里面手动进行切割。这个效果并不是我所需要的,就在这个基础上进行了修改。
主要是将切割的代码拿出来,放到碰撞检测中。
你可以把碰撞和剑 砍刀 激光绑定在一起 就可以实现切割模型,对用户的体验感急剧上升
切割代码:主要代码如下
Material Slice_material = Resources.Load<Material>("Slice");
GameObject hullObj = other.gameObject;
SlicedHull hull = hullObj.Slice(transform.position, transform.up);
GameObject LowerHull = hull.CreateLowerHull(hullObj, Slice_material);
LowerHull.AddComponent<Rigidbody>().AddExplosionForce(500, transform.position - Vector3.right, 10f);
LowerHull.AddComponent<MeshCollider>().convex = true;
GameObject UpperHull = hull.CreateUpperHull(hullObj, Slice_material);
UpperHull.AddComponent<Rigidbody>().AddExplosionForce(500, transform.position + Vector3.right, 10f);
UpperHull.AddComponent<MeshCollider>().convex = true;
示例项目:项目链接
更多推荐
所有评论(0)