Chopping trees

Hi, I have been here for awhile and can’t get trees to chop down. I need help.
A answer would be much appreciated.

var treeHealth = 5;

var tree = GameObject;
var hit = GameObject;

var logs = GameObject;

var speed : int = 8;

function Start()

{
rigidbody.isKinematic = false;
}

And yes I’m new to coding

1 Answer

1

A simple way would be to use OnMouseDown. Just make sure you have a collider on the trees, here is an example of how you might do the code:

function OnMouseDown () {
    treeHealth -= 1;
    if(treeHealth <= 0)
    {
         Instantiate(logs, transform.position, transform.rotation);
         Destroy(this);
    }
}