Car customization should fully work

This commit is contained in:
2024-04-23 13:03:15 +02:00
parent 5eb69aaa38
commit 83ae0f6e22
14 changed files with 2118 additions and 273 deletions

View File

@@ -33,8 +33,7 @@ public class AgentControllerV6 : Agent
public int distanceBetweenCheckpoints = 5;
public bool ignoreMentalPain = false;
// Start is called before the first frame update
void Start()
void Awake()
{
rigidBody = GetComponent<Rigidbody>();
// Find all child GameObjects that have the WheelControl script attached
@@ -42,7 +41,11 @@ public class AgentControllerV6 : Agent
startPosition = transform.localPosition;
startRotation = transform.localRotation;
}
protected override void OnDisable()
{
return;
}
public override void OnEpisodeBegin()

View File

@@ -8,6 +8,7 @@ using UnityEngine.UI;
public class Garage : MonoBehaviour
{
GameObject CurrentCar;
string currentColor = "Default";
public Button[] CarButtons;
public GameObject[] Garages;
public GameObject[] CarBodies;
@@ -15,6 +16,7 @@ public class Garage : MonoBehaviour
public Material[] Colors;
quaternion currentRotation;
public Button startButton;
public GameObject carData;
void Start()
{
CarButtons[0].onClick.AddListener(SelectHotrod);
@@ -64,11 +66,14 @@ public class Garage : MonoBehaviour
Garages[i].SetActive(true);
CurrentCar = CarBodies[i];
CurrentCar.transform.rotation = currentRotation;
currentColor = "Default";
}
void startGame()
{
SceneManager.LoadScene("Racetrack mini");
carData.GetComponent<CarData>().carType = CurrentCar.name;
carData.GetComponent<CarData>().carColor = currentColor;
}
void SelectHotrod()
@@ -115,71 +120,83 @@ public class Garage : MonoBehaviour
{
Material color = Colors[0];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Black";
}
void SelectBlue()
{
Material color = Colors[1];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Blue";
}
void SelectBrown()
{
Material color = Colors[2];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Brown";
}
void SelectGray()
{
Material color = Colors[3];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Gray";
}
void SelectGreen()
{
Material color = Colors[4];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Green";
}
void SelectOrange()
{
Material color = Colors[5];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Orange";
}
void SelectPink()
{
Material color = Colors[6];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Pink";
}
void SelectRed()
{
Material color = Colors[7];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Red";
}
void SelectTurquoise()
{
Material color = Colors[8];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Turquoise";
}
void SelectViolet()
{
Material color = Colors[9];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Violet";
}
void SelectWhite()
{
Material color = Colors[10];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "White";
}
void SelectYellow()
{
Material color = Colors[11];
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
currentColor = "Yellow";
}
}

View File

@@ -1,10 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class CarData : MonoBehaviour
{
public GameObject playerCar;
public string carType;
public string carColor;
private void Awake() {
DontDestroyOnLoad(gameObject);
}

View File

@@ -1,25 +1,92 @@
using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using Unity.Burst.Intrinsics;
using UnityEngine;
public class CarLoader : MonoBehaviour
{
public GameObject Hotrod;
GameObject playerCar;
public GameObject[] Cars;
string carType;
string carColor;
public Material[] Colors;
public CinemachineVirtualCamera vcam;
void Start()
{
playerCar = GameObject.Find("Car Data").GetComponent<CarData>().playerCar;
replaceCar(Hotrod);
carType = GameObject.Find("Car Data").GetComponent<CarData>().carType;
carColor = GameObject.Find("Car Data").GetComponent<CarData>().carColor;
foreach (GameObject car in Cars)
{
if (car.name == carType)
{
replaceCar(car, carColor);
}
}
}
void replaceCar(GameObject car)
void replaceCar(GameObject car, string color)
{
Transform carTransform = car.transform;
car.GetComponent<carcontrolv2>().enabled = true;
car.GetComponent<AgentControllerV6>().enabled = false;
playerCar.transform.position = carTransform.position;
playerCar.transform.rotation = carTransform.rotation;
playerCar.transform.localScale = carTransform.localScale;
vcam.Follow = car.transform;
vcam.LookAt = car.transform;
if (color == "Default")
{
return;
}
if (color == "Black")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[0]);
}
if (color == "Blue")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[1]);
}
if (color == "Brown")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[2]);
}
if (color == "Gray")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[3]);
}
if (color == "Green")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[4]);
}
if (color == "Orange")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[5]);
}
if (color == "Pink")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[6]);
}
if (color == "Red")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[7]);
}
if (color == "Turquoise")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[8]);
}
if (color == "Violet")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[9]);
}
if (color == "White")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[10]);
}
if (color == "Yellow")
{
car.GetComponent<ChangeCarColor>().ChangeColor(Colors[11]);
}
}
}

View File

@@ -128,7 +128,7 @@ public class carcontrolv2 : MonoBehaviour
if (other.gameObject.tag == "Wall")
{
audio.Play();
// audio.Play();
}
}
}