I want to write a script that will destroy a tree when three is clicked 3 times but script is stopping on “hp = 3”. Thank you for help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SCINANIE : MonoBehaviour
{
public Animator animacja;
public Animator anim;
public Canvas text;
public Canvas textno;
private bool intree;
public Canvas A, B, C, D;
public GameObject axe, player, drzewo;
// Use this for initialization
void Start()
{
text.enabled = false;
textno.enabled = false;
intree = false;
animacja.enabled = false;
A.enabled = false;
B.enabled = false;
C.enabled = false;
D.enabled = false;
anim.enabled = false;
axe.SetActive(true);
}
// Update is called once per frame
void FixedUpdate()
{
}
void OnTriggerStay(Collider other)
{
var item = player.GetComponent<items>();
if (other.tag == "Player")
{
if (item.axe == true)
{
text.enabled = true;
textno.enabled = false;
intree = true;
Debug.Log("In trigger.");
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Invoke("one", 0.1f);
textno.enabled = false;
}
else
{
text.enabled = true;
textno.enabled = false;
}
}
else
{
text.enabled = false;
textno.enabled = true;
}
}
}
void one()
{
A.enabled = false;
B.enabled = false;
C.enabled = true;
D.enabled = false;
Debug.Log("hp = 3");
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Invoke("two", 0.1f);
}
}
void two()
{
A.enabled = false;
B.enabled = true;
C.enabled = false;
D.enabled = false;
Debug.Log("hp = 2");
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Invoke("three", 0.1f);
}
}
void three()
{
A.enabled = true;
B.enabled = false;
C.enabled = false;
D.enabled = false;
Debug.Log("hp = 1");
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Invoke("four", 0.1f);
}
}
void four()
{
A.enabled = false;
B.enabled = false;
C.enabled = false;
D.enabled = false;
Debug.Log("hp = 0");
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Invoke("six", 0.1f);
}
}
void six()
{
A.enabled = false;
B.enabled = false;
C.enabled = false;
D.enabled = false;
animacja.enabled = true;
anim.enabled = false;
text.enabled = false;
textno.enabled = false;
Invoke("Cut", 9.7f);
}
void OnTriggerExit(Collider other)
{
intree = false;
text.enabled = false;
textno.enabled = false;
}
void Cut()
{
Destroy(gameObject);
}
}