SebastianLawe

Untitled

Feb 25th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Destructible : MonoBehaviour {
  5.     public int _health;
  6.     public bool _destroy;
  7.     public float _xDestructionRate;
  8.     public float _yDestructionRate;
  9.     public float _zDestructionRate;
  10.     public float _xLimit;
  11.     public float _yLimit;
  12.     public float _zLimit;
  13.     private Mesh mesh;
  14.  
  15.     // Use this for initialization
  16.     void Start() {
  17.         mesh = GetComponent<MeshFilter>().mesh;
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void FixedUpdate() {
  22.         if (_destroy) {
  23.             Vector3[] verts = mesh.vertices;
  24.             for (int i = 0; i < verts.Length; i++) {
  25.                 verts[i] = new Vector3(
  26.                     verts[i].x - (verts[i].x > _xLimit ? _xDestructionRate : 0),
  27.                     verts[i].y - (verts[i].y > _xLimit ? _yDestructionRate : 0),
  28.                     verts[i].z - (verts[i].z > _zLimit ? _zDestructionRate : 0));
  29.             }
  30.             mesh.vertices = verts;
  31.             mesh.RecalculateBounds();
  32.             mesh.RecalculateNormals();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment