public void MakeGameobject(MeshDestroy original, bool canCutChild) { GameObject = new GameObject(original.name); GameObject.transform.position = original.transform.position; GameObject.transform.rotation = original.transform.rotation; GameObject.transform.localScale = original.transform.localScale; var mesh = new Mesh(); mesh.name = original.GetComponent <MeshFilter>().mesh.name; mesh.vertices = Vertices; mesh.normals = Normals; mesh.uv = UV; for (var i = 0; i < Triangles.Length; i++) { mesh.SetTriangles(Triangles[i], i, true); } Bounds = mesh.bounds; var renderer = GameObject.AddComponent <MeshRenderer>(); renderer.materials = original.GetComponent <MeshRenderer>().materials; var filter = GameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; var collider = GameObject.AddComponent <MeshCollider>(); collider.convex = true; var rigidbody = GameObject.AddComponent <Rigidbody>(); var meshDestroy = GameObject.AddComponent <MeshDestroy>(); meshDestroy.CutCascades = original.CutCascades; meshDestroy.ExplodeForce = original.ExplodeForce; //Custom properties GameObject.layer = 11; //ignore Player if (canCutChild) { var enemyScript = GameObject.AddComponent <DummyEnemy>(); enemyScript.vfx = original.GetComponent <DummyEnemy>().vfx; } Destroy(GameObject, original.childernLifeTime); }
public void MakeGameobject(MeshDestroy original) { GameObject = new GameObject(original.name); GameObject.transform.position = original.transform.position; GameObject.transform.rotation = original.transform.rotation; GameObject.transform.localScale = original.transform.localScale; var mesh = new Mesh(); mesh.name = original.GetComponent <MeshFilter>().mesh.name; mesh.vertices = Vertices; mesh.normals = Normals; mesh.uv = UV; for (var i = 0; i < Triangles.Length; i++) { mesh.SetTriangles(Triangles[i], i, true); } Bounds = mesh.bounds; var renderer = GameObject.AddComponent <MeshRenderer>(); renderer.materials = original.GetComponent <MeshRenderer>().materials; var filter = GameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; var collider = GameObject.AddComponent <MeshCollider>(); try { collider.convex = true; var rigidbody = GameObject.AddComponent <Rigidbody>(); } catch (Exception e) { Debug.Log("Mesh Destroy error: " + e.Message); } //var meshDestroy = GameObject.AddComponent<MeshDestroy>(); //meshDestroy.CutCascades = original.CutCascades; //meshDestroy.ExplodeForce = original.ExplodeForce; }
public void MakeGameobject(MeshDestroy original) { _gameObject = new GameObject(original.name); _gameObject.transform.position = original.transform.position; _gameObject.transform.rotation = original.transform.rotation; _gameObject.transform.localScale = original.transform.localScale; var mesh = new Mesh(); mesh.name = original.GetComponent <MeshFilter>().mesh.name; mesh.vertices = Vertices; mesh.normals = Normals; mesh.uv = UV; for (var i = 0; i < Triangles.Length; i++) { mesh.SetTriangles(Triangles[i], i, true); } Bounds = mesh.bounds; var renderer = _gameObject.AddComponent <MeshRenderer>(); renderer.materials = original.GetComponent <MeshRenderer>().materials; var filter = _gameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; var collider = _gameObject.AddComponent <MeshCollider>(); collider.convex = true; var rigidbody = _gameObject.AddComponent <Rigidbody>(); var meshDestroy = _gameObject.AddComponent <MeshDestroy>(); meshDestroy.CutCascades = original.CutCascades; meshDestroy.ExplodeForce = original.ExplodeForce; _gameObject.SetActive(false); _gameObject.transform.parent = original.transform; original.fragments.Add(_gameObject); }
public void MakeGameobject(MeshDestroy original) { GameObject = new GameObject(original.name); GameObject.transform.position = original.transform.position; GameObject.transform.rotation = original.transform.rotation; GameObject.transform.localScale = original.transform.localScale; var mesh = new Mesh(); mesh.name = original.GetComponent <MeshFilter>().mesh.name; mesh.vertices = Vertices; mesh.normals = Normals; mesh.uv = UV; for (var i = 0; i < Triangles.Length; i++) { mesh.SetTriangles(Triangles[i], i, true); } Bounds = mesh.bounds; var renderer = GameObject.AddComponent <MeshRenderer>(); renderer.materials = original.GetComponent <MeshRenderer>().materials; var filter = GameObject.AddComponent <MeshFilter>(); filter.mesh = mesh; var collider = GameObject.AddComponent <MeshCollider>(); collider.convex = true; var rigidbody = GameObject.AddComponent <Rigidbody>(); // var meshDestroy = GameObject.AddComponent<SelfDestroy>(); // убираю его чтоб на завис комп и чтоб не ломалось дальше // meshDestroy.CutCascades = original.CutCascades; // meshDestroy.ExplodeForce = original.ExplodeForce; }