Hey guys.
My mate and i we are in pretty early stage of our project. We gonna try tochange our menu by script but it doesnt work the way we want it to.
About the script:
I’ve just added the function which provides us with the problem. We open a panel where we can buy our factory depending on which profession we chosen before (case 1 and 2). As we got 500 money we are able to click the button and buy the factory “Button_Betrieb_Kaufen”.
We deactivate the button and want another one to appear on the same spot - its the “Button_Betrieb_Arbeiten” Button, but it won’t show up at all.
I thought it could be a problem to do it by GameObject.Find so i also tried it by GetComponent with a var GameObject for both buttons to get a clear reference.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CityFunction : MonoBehaviour
{
// public Text CharName;
// private int Profession;
[SerializeField]
private Text CharMoneyText = null;
private Dictionary<string, int> Produkte = new Dictionary<string, int>();
private int CharMoneyInt = 0;
private int WorkInMine = 50;
public string CharNameTxt;
public int Vorwahl_Profession;
public GameObject Panel_Baecker;
public GameObject Panel_Gerber;
public void Buy()
{
if (CharMoneyInt >= 500)
{
switch (Vorwahl_Profession)
{
case (1):
Debug.Log(CharMoneyInt);
CharMoneyInt = CharMoneyInt - 500;
GlobalControl.Instance.CharMoney = CharMoneyInt;
GameObject.Find("Button_Betrieb_Kaufen").SetActive(false);
GameObject.Find("Button_Betrieb_Arbeiten").SetActive(true);
GameObject.Find("Kosten").SetActive(false);
GameObject.Find("Produkt").SetActive(true);
CharMoneyText.text = CharMoneyInt + " Taler";
break;
case (2):
CharMoneyInt = CharMoneyInt - 500;
GlobalControl.Instance.CharMoney = CharMoneyInt;
GameObject.Find("Button_Betrieb_Kaufen").SetActive(false);
GameObject.Find("Kosten").SetActive(false);
GameObject.Find("Button_Betrieb_Arbeiten").SetActive(true);
GameObject.Find("Produkt").SetActive(true);
CharMoneyText.text = CharMoneyInt + " Taler";
break;
default:
break;
}
}
}
I’ve just added those small part where we have the problem - guess the other functions in here shouldnt make any troubles with it.
And of course - i found another solution for it. But it is just some kind of “do it another way because you dont understand it”, BUT i want to understand why it doesnt work that way like i mentioned in this code.
Hopefully anybody can help us to get an idea about whats wrong - and sorry our variables are both englisch and german mixed ^^
Greetings
Terotox