Hello guys, I’m trying to make a game where u can cut down trees, but when I tested my script it didn’t work at all. This script is for cutting down trees. When I put TakeDmg and Destroytree in the private void OnTriggerEnter2D(Collider2D other) it works fine, but when I add if(Input.GetKey(KeyCode.E)), it stops working
I really don’t know that’s the problem.
public int treeHp;
public GameObject logPrefab;
public Animator anim;
private void OnTriggerEnter2D(Collider2D other){
if(Input.GetKey(KeyCode.E)){
TakeDmg();
Destroytree();
}
}
public void TakeDmg(){
//animatie si particule de la copac
anim.SetTrigger("TreeDamage");
treeHp = treeHp -1;
}
public void Destroytree(){
if(treeHp <= 0){
//spawn la loguri
Destroy(gameObject);
}
}
Thanks