Search Unity

Counting down with a game manager

Discussion in 'Scripting' started by Devivk, Jun 20, 2019.

  1. Devivk

    Devivk

    Joined:
    Jul 19, 2018
    Posts:
    5
    Hello,

    I am trying to get my Game manager to count down when you use a Key on a chest. The problem I am having is I pick up the Key and the UI still states I have 0 Keys. Then when I use the key on the chest it will say I have 1 key even though the key has already been used. Below is a segment of the code I am having trouble with. As well as my game manager script


    if (collision.gameObject.tag == "BChest" && GameManager.Instance.BronzeK >0)
    {
    Bronze.text = GameManager.Instance.BronzeK--.ToString();

    CoinText.text = GameManager.Instance.CCount++.ToString();
    }

    --------------------------------------------------------------------------------------------------------------------------------------------

    public class GameManager: MonoBehaviour
    {
    public static GameManager Instance { get; private set; }

    public int CCount;
    public int CollCount;
    public int BronzeK;
    public int SilverK;
    public int GoldK;
    public int WraithK;
    public int Mkills;









    private void Awake()
    {
    if (Instance == null)
    {
    Instance = this;
    DontDestroyOnLoad(gameObject);
    }
    else
    {
    Destroy(gameObject);
    }
     
    Last edited: Jun 20, 2019
  2. Devivk

    Devivk

    Joined:
    Jul 19, 2018
    Posts:
    5
    The issue has been resolved I found a different method that works much better.