using System.Collections; using System.Collections.Generic; using Unity.Mathematics; using UnityEngine; using UnityEngine.UI; public class Garage : MonoBehaviour { GameObject CurrentCar; public Button[] CarButtons; public GameObject[] Garages; public GameObject[] CarBodies; public Button[] ColorButtons; public Material[] Colors; quaternion currentRotation; void Start() { CarButtons[0].onClick.AddListener(SelectHotrod); CarButtons[1].onClick.AddListener(SelectCoupe); CarButtons[2].onClick.AddListener(SelectBolide); CarButtons[3].onClick.AddListener(SelectIcecreamTruck); CarButtons[4].onClick.AddListener(SelectSportscar); CarButtons[5].onClick.AddListener(SelectSchoolBus); CarButtons[6].onClick.AddListener(SelectBulldozer); CarButtons[7].onClick.AddListener(SelectPicupTruck); 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(); } private void FixedUpdate() { CurrentCar.transform.eulerAngles += Vector3.up * 0.7f; currentRotation = CurrentCar.transform.rotation; } void disable() { foreach (GameObject carGarage in Garages) { carGarage.SetActive(false); } } void SelectCar(int i) { disable(); Garages[i].SetActive(true); CurrentCar = CarBodies[i]; CurrentCar.transform.rotation = currentRotation; } void SelectHotrod() { SelectCar(0); } void SelectCoupe() { SelectCar(1); } void SelectBolide() { SelectCar(2); } void SelectIcecreamTruck() { SelectCar(3); } void SelectSportscar() { SelectCar(4); } void SelectSchoolBus() { SelectCar(5); } void SelectBulldozer() { SelectCar(6); } void SelectPicupTruck() { SelectCar(7); } 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); } }