Skip to content

Commit

Permalink
added new effects + gui
Browse files Browse the repository at this point in the history
  • Loading branch information
maxilevi committed Nov 10, 2017
1 parent d9005d0 commit 9e935ea
Show file tree
Hide file tree
Showing 10 changed files with 539 additions and 33 deletions.
Binary file added Assets/ColabThi.otf
Binary file not shown.
22 changes: 22 additions & 0 deletions Assets/ColabThi.otf.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions Assets/Explode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// C#
// SplitMeshIntoTriangles.cs
using UnityEngine;
using System.Collections;

public class Explode : MonoBehaviour
{

void Update(){
if(Input.GetMouseButtonDown(0))
StartCoroutine(SplitMesh());
}

IEnumerator SplitMesh ()
{
MeshFilter MF = GetComponent<MeshFilter>();
MeshRenderer MR = GetComponent<MeshRenderer>();
Mesh M = MF.mesh;
Vector3[] verts = M.vertices;
Vector3[] normals = M.normals;
Vector2[] uvs = M.uv;
for (int submesh = 0; submesh < M.subMeshCount; submesh++)
{
int[] indices = M.GetTriangles(submesh);
for (int i = 0; i < indices.Length; i += 3)
{
Vector3[] newVerts = new Vector3[3];
Vector3[] newNormals = new Vector3[3];
Vector2[] newUvs = new Vector2[3];
for (int n = 0; n < 3; n++)
{
int index = indices[i + n];
newVerts[n] = verts[index];
newUvs[n] = uvs[index];
newNormals[n] = normals[index];
}
Mesh mesh = new Mesh();
mesh.vertices = newVerts;
mesh.normals = newNormals;
mesh.uv = newUvs;

mesh.triangles = new int[] { 0, 1, 2, 2, 1, 0 };

GameObject GO = new GameObject("Triangle " + (i / 3));
GO.transform.position = transform.position;
GO.transform.rotation = transform.rotation;
GO.AddComponent<MeshRenderer>().material = MR.materials[submesh];
GO.AddComponent<MeshFilter>().mesh = mesh;
GO.AddComponent<BoxCollider>();
GO.AddComponent<Rigidbody>().AddExplosionForce(100, transform.position, 30);

Destroy(GO, 5 + Random.Range(0.0f, 5.0f));
}
}
MR.enabled = false;

Time.timeScale = 0.2f;
yield return new WaitForSeconds(0.8f);
Time.timeScale = 1.0f;
Destroy(gameObject);
}
}
13 changes: 13 additions & 0 deletions Assets/Explode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e935ea

Please sign in to comment.