So I have a basic progress bar that runs in my woodcutting script. When I click on the tree that its attached to it set to setactive(true), and once its destroyed it goes back to setactive(false). However when I run the SetActive(false) in start it allows me to click on one tree, but not the other. When I take out SetActive(false) in start, the progress bar shows at start up, when I click on tree it works, then it hides the bar, and then when I click on the second tree it does the same thing(which is how its supposed to be). What am I doing wrong here? I basically want the progressbar to not show till I click on the tree, and hide when its done.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Woodcutting : MonoBehaviour
{
Inventory inventory;
public float timeRemaining = 10f;
private bool counterActive = false;
public Transform LoadingBar;
[SerializeField]
private float currentAmount;
[SerializeField]
private float speed;
GameObject progressBar;
GameObject loadingBar;
// Use this for initialization
void Start()
{
inventory = GameObject.Find("Inventory").GetComponent<Inventory>();
progressBar = GameObject.Find("ProgressBar");
progressBar.SetActive(false);
}
void OnMouseDown()
{
counterActive = true;
}
void Update()
{
if (timeRemaining > 0 && counterActive == true)
{
progressBar.SetActive(true);
Debug.Log("Waitting..." + timeRemaining);
currentAmount -= speed * Time.deltaTime;
LoadingBar.GetComponent<Image>().fillAmount = currentAmount / 100;
timeRemaining -= Time.deltaTime;
if (timeRemaining <= 0)
{
inventory.AddItem(0);
progressBar.SetActive(false);
Destroy(gameObject);
}
}
}
}