Search Unity

Destorying Terrain Trees

Discussion in 'Scripting' started by RandomEDP, Jul 29, 2019.

  1. RandomEDP

    RandomEDP

    Joined:
    Apr 30, 2019
    Posts:
    1
    Hello I am currently developing a moblie FPS Survial game in which you can cut down trees, I have written most of the code to this but I can't furgue out how to remove a terrain tree. Here is the code.
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using System;
    6.  
    7. public class Tree : MonoBehaviour
    8. {
    9.     [HideInInspector]
    10.     public static float health = 20f;
    11.     public GameObject Pile;
    12.     public GameObject self;
    13.     public MeshRenderer mesh;
    14.     public CapsuleCollider cap;
    15.  
    16.  
    17.     public void Start()
    18.     {
    19.         health = 20f;
    20.     }
    21.  
    22.     public void hit()
    23.     {
    24.         health -= 10f;
    25.         Debug.Log(health);
    26.         TextItem.WoodCount += 1;
    27. //      Destroy Tree
    28.         if (health <= 0)
    29.         {
    30.             Debug.Log("Tree Has No Health");
    31.             Destroy(gameObject);
    32.         }
    33.     }
    34. }
    35.  
    36.  
    Thanks in advance
    Ethan