Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Destructible : MonoBehaviour {
- public int _health;
- public bool _destroy;
- public float _xDestructionRate;
- public float _yDestructionRate;
- public float _zDestructionRate;
- public float _xLimit;
- public float _yLimit;
- public float _zLimit;
- private Mesh mesh;
- // Use this for initialization
- void Start() {
- mesh = GetComponent<MeshFilter>().mesh;
- }
- // Update is called once per frame
- void FixedUpdate() {
- if (_destroy) {
- Vector3[] verts = mesh.vertices;
- for (int i = 0; i < verts.Length; i++) {
- verts[i] = new Vector3(
- verts[i].x - (verts[i].x > _xLimit ? _xDestructionRate : 0),
- verts[i].y - (verts[i].y > _xLimit ? _yDestructionRate : 0),
- verts[i].z - (verts[i].z > _zLimit ? _zDestructionRate : 0));
- }
- mesh.vertices = verts;
- mesh.RecalculateBounds();
- mesh.RecalculateNormals();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment