using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Garage : MonoBehaviour { GameObject CurrentCar; public Button HotrodButton; public GameObject HotrodGarage; public GameObject Hotrod; public Button RacecarButton; public GameObject RacecarGarage; public GameObject Racecar; public Button FordButton; public GameObject FordGarage; public GameObject Ford; public Button[] ColorButtons; public Material[] Colors; // Start is called before the first frame update void Start() { HotrodButton.onClick.AddListener(SelectHotrod); RacecarButton.onClick.AddListener(SelectRacecar); FordButton.onClick.AddListener(SelectFord); ColorButtons[0].onClick.AddListener(SelectBlack); ColorButtons[1].onClick.AddListener(SelectBlue); ColorButtons[2].onClick.AddListener(SelectBrown); ColorButtons[3].onClick.AddListener(SelectGray); ColorButtons[4].onClick.AddListener(SelectGreen); ColorButtons[5].onClick.AddListener(SelectOrange); ColorButtons[6].onClick.AddListener(SelectPink); ColorButtons[7].onClick.AddListener(SelectRed); ColorButtons[8].onClick.AddListener(SelectTurquoise); ColorButtons[9].onClick.AddListener(SelectViolet); ColorButtons[10].onClick.AddListener(SelectWhite); ColorButtons[11].onClick.AddListener(SelectYellow); disable(); SelectHotrod(); } void enable(GameObject carGarage) { carGarage.SetActive(true); } void disable() { HotrodGarage.SetActive(false); RacecarGarage.SetActive(false); FordGarage.SetActive(false); } void SelectHotrod() { disable(); enable(HotrodGarage); CurrentCar = Hotrod; } void SelectRacecar() { disable(); enable(RacecarGarage); CurrentCar = Racecar; } void SelectFord() { disable(); enable(FordGarage); CurrentCar = Ford; } void SelectBlack() { Material color = Colors[0]; CurrentCar.GetComponent().ChangeColor(color); } void SelectBlue() { Material color = Colors[1]; CurrentCar.GetComponent().ChangeColor(color); } void SelectBrown() { Material color = Colors[2]; CurrentCar.GetComponent().ChangeColor(color); } void SelectGray() { Material color = Colors[3]; CurrentCar.GetComponent().ChangeColor(color); } void SelectGreen() { Material color = Colors[4]; CurrentCar.GetComponent().ChangeColor(color); } void SelectOrange() { Material color = Colors[5]; CurrentCar.GetComponent().ChangeColor(color); } void SelectPink() { Material color = Colors[6]; CurrentCar.GetComponent().ChangeColor(color); } void SelectRed() { Material color = Colors[7]; CurrentCar.GetComponent().ChangeColor(color); } void SelectTurquoise() { Material color = Colors[8]; CurrentCar.GetComponent().ChangeColor(color); } void SelectViolet() { Material color = Colors[9]; CurrentCar.GetComponent().ChangeColor(color); } void SelectWhite() { Material color = Colors[10]; CurrentCar.GetComponent().ChangeColor(color); } void SelectYellow() { Material color = Colors[11]; CurrentCar.GetComponent().ChangeColor(color); } }