// Update is called once per frame // Access the currentStatus (colours and font) and sets the header, background, and font size void Update() { GameObject go = GameObject.Find("CurrStatus"); // make sure we have a CurrStatus GameObject if (go == null) { Debug.LogError("Failed to find an object named CurrStatus"); this.enabled = false; return; } CurrStatus cs = go.GetComponent <CurrStatus>(); // case 1 : GameObject TextOb is a single gameObject of type text // access text component and edit it try { TextOb.GetComponent <Text>().fontSize = cs.FontSize; } // case 2 : GameObject TextOb is an Empty with multiple text object children // this is the case in Tutorial, where all boxes of text should change size // access the children of type text and itterate through them, changing the font size catch (NullReferenceException) { Text[] textList = TextOb.GetComponentsInChildren <Text>(); for (int i = 0; i < textList.Length; i++) { textList[i].GetComponent <Text>().fontSize = cs.FontSize; } } // Only one case for colours, just change them. BackgroundColourOb.GetComponent <Image>().color = cs.BackgroundColour; HeaderColourOb.GetComponent <Image>().color = cs.HeaderColour; }
// Start is called before the first frame update void Start() { // check if there is already an instance of CurrStatus if (instance != null) { // there is already an instance of status, self destory Destroy(this); return; } // If there is not, become the CurrStatus and become indestructable // Unity Singleton Design Pattern instance = this; DontDestroyOnLoad(this.gameObject); }