hello, I have a script that allows me to place buildings on buildplaces (areas that allow me to place my buildings on) and I’m supposed to only be able to place these buildings if the variable MyMoney, (which is constantly going up) equals 10. however, it won’t allow me to place buildings even when the MyMoney variable equals 10. (I’m referencing the MyMoney variable from a script called MoneyManager) can someone help me? here is my script:
using UnityEngine;
using System.Collections;
public class Buildplace : MonoBehaviour
{
// The Tower that should be built
public GameObject factoryPrefab;
private MoneyManager moneyManager;
void OnMouseUpAsButton()
{
if (moneyManager.GetComponent<MoneyManager>().MyMoney >= 10.0f)
{
// Build Tower above Buildplace
GameObject g = (GameObject)Instantiate(factoryPrefab);
g.transform.position = transform.position + Vector3.up;
}
}
}
here is the MoneyManager script where I get the MyMoney variable from:
using UnityEngine;
using System.Collections;
public class MoneyManager : MonoBehaviour
{
public float MyMoney;
IEnumerator Money()
{
// suspend execution for 5 seconds
yield return new WaitForSeconds(5);
MyMoney += 1.0f;
yield return StartCoroutine("Start");
}
IEnumerator Start()
{
// Start function WaitAndPrint as a coroutine
yield return StartCoroutine("Money");
}
}