161 lines
4.4 KiB
C#
161 lines
4.4 KiB
C#
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<MeshFilter>().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>();
|
|
// //meshRenderer.sharedMaterial = new Material(Shader.Find("Standard"));
|
|
|
|
// MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
|
|
|
|
// 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<MeshCollider>();
|
|
// meshColl.sharedMesh = meshFilter.sharedMesh;
|
|
|
|
// ShatterableGlass shattGlas = GetComponent<ShatterableGlass>();
|
|
// shattGlas.enabled = true;
|
|
|
|
// AudioSource audioSource = GetComponent<AudioSource>();
|
|
// audioSource.enabled = true;
|
|
|
|
// Trigger trigger = GetComponent<Trigger>();
|
|
// trigger.enabled = true;
|
|
//}
|
|
|
|
public void Start()
|
|
{
|
|
//MeshRenderer meshRenderer = gameObject.AddComponent<MeshRenderer>();
|
|
//meshRenderer.sharedMaterial = new Material(Shader.Find("Standard"));
|
|
|
|
MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
|
|
|
|
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<MeshCollider>();
|
|
//meshColl.sharedMesh = meshFilter.sharedMesh;
|
|
|
|
//MeshCollider meshColl = gameObject.AddComponent<MeshCollider>();
|
|
//meshColl.convex = true;
|
|
//meshColl.isTrigger = true;
|
|
//meshColl.sharedMesh = meshFilter.sharedMesh;
|
|
|
|
BoxCollider boxColl = gameObject.AddComponent<BoxCollider>();
|
|
boxColl.isTrigger = true;
|
|
|
|
//ShatterableGlass shattGlas = GetComponent<ShatterableGlass>();
|
|
//shattGlas.enabled = true;
|
|
|
|
ShatterableGlass shattGlass = gameObject.AddComponent<ShatterableGlass>();
|
|
shattGlass.GlassSidesMaterial = GlassSide;
|
|
shattGlass.ShatterButNotBreak = true;
|
|
|
|
//shattGlass.GlassSides = GlassMat;
|
|
|
|
AudioSource audioSource = GetComponent<AudioSource>();
|
|
audioSource.enabled = true;
|
|
|
|
//Trigger trigger = GetComponent<Trigger>();
|
|
//trigger.enabled = true;
|
|
|
|
gameObject.tag="ShatterableGlass";
|
|
}
|
|
}
|