Hi there,
I have made an UI with some buttons and I’d like to instantiate things when i click those, but only if i have enough gold. Spawning works fine without the if statement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnCreep : MonoBehaviour
{
public GameObject Creep;
public Transform Spawnpoint;
public int Cost;
private crntGold gold;
public void SpawnThis()
{
//gold = GetComponent<crntGold>();
// if (gold.gold >= 10)
// {
Instantiate(Creep, Spawnpoint.position, Spawnpoint.rotation);
// gold.gold = gold.gold - Cost;
// }
}
}
how come, and how could i change this? for sake of completeness, here is my gold script, maybe the error is there:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class crntGold : MonoBehaviour
{
public int gold;
public Text uigold;
private GoldCounter goldCounter;
void Start()
{
gold = 100;
uigold.text = "Gold:" + gold.ToString();
goldCounter = GetComponent<GoldCounter>();
}
// Update is called once per frame
void Update()
{
if (goldCounter.timer == 0.0f) ;
{
uigold.text = "Gold:" + gold.ToString();
}
}
}
thanks for any replys in advance!