ofb/Assets/Scripts/GameUIController.cs
2023-05-01 17:30:54 -07:00

78 lines
2.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameUIController : MonoBehaviour
{
[Header("Instruments (backgrounds)")]
public GameObject trumpetBackground;
public GameObject tambourineBackground;
public GameObject clarinetBackground;
[HideInInspector] public GameObject trumpetUI;
[HideInInspector] public GameObject tambourineUI;
[HideInInspector] public GameObject clarinetUI;
[Header("Other Objects")]
private StateController stateController;
void Start() {
stateController = GameObject.FindGameObjectWithTag("StateController").GetComponent<StateController>();
if (stateController == null) {
print("state controller not found");
} else {
print("yeehaw");
}
trumpetUI = trumpetBackground.transform.GetChild(0).gameObject;
tambourineUI = tambourineBackground.transform.GetChild(0).gameObject;
clarinetUI = clarinetBackground.transform.GetChild(0).gameObject;
if (!stateController.unlockedTrumpet) {
trumpetBackground.SetActive(false);
}
if (!stateController.unlockedTambourine) {
tambourineBackground.SetActive(false);
}
if (!stateController.unlockedClarinet) {
clarinetBackground.SetActive(false);
}
}
public void ToggleTrumpet(bool toggleState) {
bool curEnabled = trumpetUI.GetComponent<Image>().enabled;
if (curEnabled != toggleState) {
trumpetUI.GetComponent<Image>().enabled = toggleState;
}
}
public void ToggleTambourine(bool toggleState) {
bool curEnabled = tambourineUI.GetComponent<Image>().enabled;
if (curEnabled != toggleState) {
tambourineUI.GetComponent<Image>().enabled = toggleState;
}
}
public void ToggleClarinet(bool toggleState) {
bool curEnabled = clarinetUI.GetComponent<Image>().enabled;
if (curEnabled != toggleState) {
clarinetUI.GetComponent<Image>().enabled = toggleState;
}
}
public void ResetInstrumentUI() {
if (stateController == null) {
print("state controller null");
}
if (stateController.unlockedTrumpet) {
ToggleTrumpet(true);
}
if (stateController.unlockedTambourine) {
ToggleTambourine(true);
}
if (stateController.unlockedClarinet) {
ToggleClarinet(true);
}
}
}