Hi! I’m trying to build a tycoon and I have a text component that shows the price, and I get this error:
The funny thing is that it works perfectly for the Balance and I get no error there…
This is the code for the balance:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class pointCounterGamesMenu : MonoBehaviour
{
private Text totalPoints;
private void Awake()
{
totalPoints = transform.Find("balanceText").GetComponent<Text>();
}
// Start is called before the first frame update
void Start()
{
totalPoints.text = "Balance: " + System.Environment.NewLine + Score.GetTotalPoints().ToString();
}
// Update is called once per frame
void Update()
{
totalPoints.text = "Balance: " + System.Environment.NewLine + Score.GetTotalPoints().ToString();
}
}
And this is what I did in the editor:
It also has a “balanceText” text component, which is changed through my code.
Here’s the Code for the TycoonTextChanger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TycoonTextUpdater : MonoBehaviour
{
private Text tycoon1PriceText;
private Text tycoon1IncomeText;
private Text tycoon1UnitsText;
private void Awake()
{
tycoon1PriceText = transform.Find("Tycoon1PriceText").GetComponent<Text>();
tycoon1IncomeText = transform.Find("ProductionPerDayTextTycoon1").GetComponent<Text>();
tycoon1UnitsText = transform.Find("UnitsOwnedTextTycoon1").GetComponent<Text>();
}
// Start is called before the first frame update
void Start()
{
tycoon1PriceText.text = "BUY: " + TycoonBasic.tycoon1.price.ToString();
tycoon1IncomeText.text = "Income: " + (TycoonBasic.tycoon1.unitCount * 3).ToString() + "/day";
tycoon1UnitsText.text = "Units: " + System.Environment.NewLine + TycoonBasic.tycoon1.unitCount.ToString();
Debug.Log("Start Works");
}
// Update is called once per frame
void Update()
{
tycoon1PriceText.text = "BUY: " + TycoonBasic.tycoon1.price.ToString();
tycoon1IncomeText.text = "Income: " + (TycoonBasic.tycoon1.unitCount * 3).ToString() + "/day";
tycoon1UnitsText.text = "Units: " + System.Environment.NewLine + TycoonBasic.tycoon1.unitCount.ToString();
}
}
And in the editor, I tried attaching it to each GameObject that has the text as a child and also to the main GameObject that has the GameObjects that hold the text.
Still not working and getting that error.
If you need more code or anything, please let me know!
