- Home /
Resource Counting
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)
[code] 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);
}
}
[/code]
Answer by kaplica · Sep 15, 2017 at 08:54 AM
This is what you need:)
Sample the height at the given position defined in world space, relative to the terrain space.
https://docs.unity3d.com/ScriptReference/Terrain.SampleHeight.html
Im sorry. I dont really understand what it is. It wasnt very clear
Your answer
![](https://koobas.hobune.stream/wayback/20220612134906im_/https://answers.unity.com/themes/thub/images/avi.jpg)