Hey. Im trying to make a Resource manager. I have a system where you can chop down trees but I want ot make it so you get wood if it is fallen. I have referenced the UI and made an int but I cant figure out how I can detect if a tree has been fallen. I will reference my Tree script (The collider has a tag for the axe to work)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tree : MonoBehaviour
{
//Variables
GameObject thisTree;
public int treeHealth = 5;
public bool isFallen = false;
public void Start()
{
thisTree = transform.parent.gameObject;
}
public void Update()
{
if(treeHealth <= 0 && isFallen == false)
{
Rigidbody rb = thisTree.AddComponent<Rigidbody>();
rb.isKinematic = false;
rb.useGravity = true;
rb.AddForce(Vector3.forward, ForceMode.Impulse);
StartCoroutine(destroyTree());
isFallen = true;
}
}
public IEnumerator destroyTree()
{
yield return new WaitForSeconds(10);
Destroy(thisTree);
}
}