using System.Collections; using System.Collections.Generic; using UnityEngine; public class TriangleMaker : MonoBehaviour { //public Vector3[] newVertices; //public Vector2[] newUV; //public int[] newTriangles; //void Start() //{ // Mesh mesh = new Mesh(); // GetComponent().mesh = mesh; // mesh.vertices = newVertices; // mesh.uv = newUV; // mesh.triangles = newTriangles; //} public float width = 1.4142f*28.3f; public float height = 1*28.3f; public Material GlassSide; //public Material GlassMat; //public void Start() //{ // //MeshRenderer meshRenderer = gameObject.AddComponent(); // //meshRenderer.sharedMaterial = new Material(Shader.Find("Standard")); // MeshFilter meshFilter = gameObject.AddComponent(); // Mesh mesh = new Mesh(); // Vector3[] vertices = new Vector3[3] // { // new Vector3(0, 0, 0), // new Vector3(width, 0, 0), // new Vector3(width/2, height, 0) // }; // mesh.vertices = vertices; // int[] tris = new int[3] // { // // triangle // 0, 1, 2 // }; // mesh.triangles = tris; // Vector3[] normals = new Vector3[3] // { // -Vector3.forward, // -Vector3.forward, // -Vector3.forward // }; // mesh.normals = normals; // Vector2[] uv = new Vector2[3] // { // new Vector2(0, 0), // new Vector2(1, 0), // new Vector2(0.5f, 1) // }; // mesh.uv = uv; // meshFilter.mesh = mesh; // MeshCollider meshColl = GetComponent(); // meshColl.sharedMesh = meshFilter.sharedMesh; // ShatterableGlass shattGlas = GetComponent(); // shattGlas.enabled = true; // AudioSource audioSource = GetComponent(); // audioSource.enabled = true; // Trigger trigger = GetComponent(); // trigger.enabled = true; //} public void Start() { //MeshRenderer meshRenderer = gameObject.AddComponent(); //meshRenderer.sharedMaterial = new Material(Shader.Find("Standard")); MeshFilter meshFilter = gameObject.AddComponent(); Mesh mesh = new Mesh(); Vector3[] vertices = new Vector3[6] { new Vector3(0, 0, 0), new Vector3(width, 0, 0), new Vector3(width/2, height, 0), new Vector3(0, 0, 0.025f), new Vector3(width, 0, 0.025f), new Vector3(width/2, height, 0.025f) }; mesh.vertices = vertices; int[] tris = new int[3] { // triangle 0, 1, 2, }; mesh.triangles = tris; Vector3[] normals = new Vector3[6] { -Vector3.forward, -Vector3.forward, -Vector3.forward, -Vector3.forward, -Vector3.forward, -Vector3.forward }; mesh.normals = normals; Vector2[] uv = new Vector2[6] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(0.5f, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(0.5f, 1) }; mesh.uv = uv; meshFilter.mesh = mesh; //MeshCollider meshColl = GetComponent(); //meshColl.sharedMesh = meshFilter.sharedMesh; //MeshCollider meshColl = gameObject.AddComponent(); //meshColl.convex = true; //meshColl.isTrigger = true; //meshColl.sharedMesh = meshFilter.sharedMesh; BoxCollider boxColl = gameObject.AddComponent(); boxColl.isTrigger = true; //ShatterableGlass shattGlas = GetComponent(); //shattGlas.enabled = true; ShatterableGlass shattGlass = gameObject.AddComponent(); shattGlass.GlassSidesMaterial = GlassSide; shattGlass.ShatterButNotBreak = true; //shattGlass.GlassSides = GlassMat; AudioSource audioSource = GetComponent(); audioSource.enabled = true; //Trigger trigger = GetComponent(); //trigger.enabled = true; gameObject.tag="ShatterableGlass"; } }