Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TreeMain : MonoBehaviour {
- private GameObject tree;
- private bool callOnce;
- public int treeHealth = 5;
- public int speed = 2;
- void Start ()
- {
- callOnce = false;
- tree = this.gameObject;
- }
- void Update ()
- {
- if(treeHealth == 1)
- {
- callOnce = true;
- }
- if((treeHealth <= 0) && (callOnce == true))
- {
- tree.AddComponent<Rigidbody>();
- GetComponent<Rigidbody>().isKinematic = false;
- GetComponent<Rigidbody>().AddForce(transform.forward * speed, ForceMode.Impulse);
- DestroyTree();
- callOnce = false;
- }
- }
- IEnumerator DestroyTree()
- {
- yield return new WaitForSeconds(7);
- Destroy(tree);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement