Advertisement
nikcio

TreeMain

Sep 14th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TreeMain : MonoBehaviour {
  5.  
  6.     private GameObject tree;
  7.     private bool callOnce;
  8.  
  9.     public int treeHealth = 5;
  10.     public int speed = 2;
  11.    
  12.     void Start ()
  13.     {
  14.         callOnce = false;
  15.         tree = this.gameObject;
  16.     }
  17.    
  18.     void Update ()
  19.     {
  20.         if(treeHealth == 1)
  21.         {
  22.             callOnce = true;
  23.         }
  24.  
  25.         if((treeHealth <= 0) && (callOnce == true))
  26.         {
  27.             tree.AddComponent<Rigidbody>();
  28.             GetComponent<Rigidbody>().isKinematic = false;
  29.             GetComponent<Rigidbody>().AddForce(transform.forward * speed, ForceMode.Impulse);
  30.             DestroyTree();
  31.             Destroy(tree);
  32.             callOnce = false;
  33.         }
  34.     }
  35.  
  36.     IEnumerator DestroyTree()
  37.     {
  38.         yield return new WaitForSeconds(7);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement