Changed car controller script
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user