Changed car controller script
This commit is contained in:
@@ -29,7 +29,7 @@ public class CarLoader : MonoBehaviour
|
||||
|
||||
void replaceCar(GameObject car, string color)
|
||||
{
|
||||
car.GetComponent<carcontrolv2>().enabled = true;
|
||||
car.GetComponent<PlayerController>().enabled = true;
|
||||
car.GetComponent<AgentControllerV6>().enabled = false;
|
||||
|
||||
cam.GetComponent<CameraControl>().getCar(car);
|
||||
|
||||
@@ -16,8 +16,8 @@ public class GameController :MonoBehaviour
|
||||
public static bool RaceIsStarted { get { return true; } }
|
||||
public static bool RaceIsEnded { get { return false; } }
|
||||
|
||||
carcontrolv2 m_PlayerCar;
|
||||
List<carcontrolv2> Cars = new List<carcontrolv2>();
|
||||
PlayerController m_PlayerCar;
|
||||
List<PlayerController> Cars = new List<PlayerController>();
|
||||
int CurrentCarIndex = 0;
|
||||
|
||||
protected virtual void Awake ()
|
||||
@@ -26,17 +26,17 @@ public class GameController :MonoBehaviour
|
||||
Instance = this;
|
||||
|
||||
//Find all cars in current game.
|
||||
Cars.AddRange (GameObject.FindObjectsOfType<carcontrolv2> ());
|
||||
Cars.AddRange (GameObject.FindObjectsOfType<PlayerController> ());
|
||||
Cars = Cars.OrderBy (c => c.name).ToList();
|
||||
|
||||
foreach (var car in Cars)
|
||||
{
|
||||
var userControl = car.GetComponent<carcontrolv2>();
|
||||
var userControl = car.GetComponent<PlayerController>();
|
||||
var audioListener = car.GetComponent<AudioListener>();
|
||||
|
||||
if (userControl == null)
|
||||
{
|
||||
userControl = car.gameObject.AddComponent<carcontrolv2> ();
|
||||
userControl = car.gameObject.AddComponent<PlayerController> ();
|
||||
}
|
||||
|
||||
if (audioListener == null)
|
||||
@@ -49,7 +49,7 @@ public class GameController :MonoBehaviour
|
||||
}
|
||||
|
||||
m_PlayerCar = Cars[0];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
|
||||
if (NextCarButton)
|
||||
@@ -69,13 +69,13 @@ public class GameController :MonoBehaviour
|
||||
|
||||
private void NextCar ()
|
||||
{
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = false;
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = false;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = false;
|
||||
|
||||
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, Cars.Count);
|
||||
|
||||
m_PlayerCar = Cars[CurrentCarIndex];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
public int lapAmount;
|
||||
public GameObject[] checkpoints;
|
||||
public GameObject[] players;
|
||||
|
||||
int currentLap = 1;
|
||||
void Start()
|
||||
{
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class carcontrolv2 : MonoBehaviour
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public float motorTorque = 2000;
|
||||
public float brakeTorque = 2000;
|
||||
@@ -12,8 +12,8 @@ public class gameController1 : MonoBehaviour
|
||||
public static bool RaceIsStarted { get { return true; } }
|
||||
public static bool RaceIsEnded { get { return false; } }
|
||||
|
||||
carcontrolv2 m_PlayerCar;
|
||||
List<carcontrolv2> Cars = new List<carcontrolv2>();
|
||||
PlayerController m_PlayerCar;
|
||||
List<PlayerController> Cars = new List<PlayerController>();
|
||||
int CurrentCarIndex = 0;
|
||||
|
||||
protected virtual void Awake ()
|
||||
@@ -22,17 +22,17 @@ public class gameController1 : MonoBehaviour
|
||||
Instance = this;
|
||||
|
||||
//Find all cars in current game.
|
||||
Cars.AddRange (GameObject.FindObjectsOfType<carcontrolv2> ());
|
||||
Cars.AddRange (GameObject.FindObjectsOfType<PlayerController> ());
|
||||
Cars = Cars.OrderBy(c => c.name).ToList();
|
||||
|
||||
foreach (var car in Cars)
|
||||
{
|
||||
var userControl = car.GetComponent<carcontrolv2>();
|
||||
var userControl = car.GetComponent<PlayerController>();
|
||||
var audioListener = car.GetComponent<AudioListener>();
|
||||
|
||||
if (userControl == null)
|
||||
{
|
||||
userControl = car.gameObject.AddComponent<carcontrolv2> ();
|
||||
userControl = car.gameObject.AddComponent<PlayerController> ();
|
||||
}
|
||||
|
||||
if (audioListener == null)
|
||||
@@ -45,7 +45,7 @@ public class gameController1 : MonoBehaviour
|
||||
}
|
||||
|
||||
m_PlayerCar = Cars[0];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
|
||||
if (NextCarButton)
|
||||
@@ -65,13 +65,13 @@ public class gameController1 : MonoBehaviour
|
||||
|
||||
private void NextCar ()
|
||||
{
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = false;
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = false;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = false;
|
||||
|
||||
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, Cars.Count);
|
||||
|
||||
m_PlayerCar = Cars[CurrentCarIndex];
|
||||
m_PlayerCar.GetComponent<carcontrolv2> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user