using System.Collections; using System.Collections.Generic; using Cinemachine; using Unity.Burst.Intrinsics; using UnityEngine; public class CarLoader : MonoBehaviour { public GameObject[] Cars; string carType; string carColor; public Material[] Colors; public GameObject cam; public GameObject targetcar; void Start() { try { carType = GameObject.Find("Car Data").GetComponent().carType; carColor = GameObject.Find("Car Data").GetComponent().carColor; } catch (System.Exception) { carType = "Racecar"; carColor = "Default"; print("no loading"); } foreach (GameObject car in Cars) { if (car.name == carType) { replaceCar(car, carColor); } } } void replaceCar(GameObject car, string color) { car.GetComponent().enabled = true; car.GetComponent().enabled = false; cam.GetComponent().getCar(car); //LookAt = car.transform; if (color == "Default") { return; } if (color == "Black") { car.GetComponent().ChangeColor(Colors[0]); } if (color == "Blue") { car.GetComponent().ChangeColor(Colors[1]); } if (color == "Brown") { car.GetComponent().ChangeColor(Colors[2]); } if (color == "Gray") { car.GetComponent().ChangeColor(Colors[3]); } if (color == "Green") { car.GetComponent().ChangeColor(Colors[4]); } if (color == "Orange") { car.GetComponent().ChangeColor(Colors[5]); } if (color == "Pink") { car.GetComponent().ChangeColor(Colors[6]); } if (color == "Red") { car.GetComponent().ChangeColor(Colors[7]); } if (color == "Turquoise") { car.GetComponent().ChangeColor(Colors[8]); } if (color == "Violet") { car.GetComponent().ChangeColor(Colors[9]); } if (color == "White") { car.GetComponent().ChangeColor(Colors[10]); } if (color == "Yellow") { car.GetComponent().ChangeColor(Colors[11]); } } }