Spectating
This commit is contained in:
@@ -5,7 +5,7 @@ using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
//script from FREAKINGREX, but minor changes to integrate it proberly
|
||||
//script from FREAKINGREX, but changes to integrate it proberly/ work how we want it to work
|
||||
//https://assetstore.unity.com/packages/templates/systems/arcade-car-controller-lite-version-145489
|
||||
|
||||
public class CameraControl :MonoBehaviour
|
||||
@@ -68,6 +68,7 @@ public class CameraControl :MonoBehaviour
|
||||
|
||||
transform.position = Vector3.LerpUnclamped (transform.position, TargetPoint, Time.deltaTime * ActivePreset.SetPositionSpeed);
|
||||
|
||||
|
||||
if (Input.GetKeyDown (SetCameraKey))
|
||||
{
|
||||
SetNextCamera ();
|
||||
@@ -111,6 +112,7 @@ public class CameraControl :MonoBehaviour
|
||||
|
||||
public void UpdateActiveCamera ()
|
||||
{
|
||||
|
||||
if (ActivePreset != null)
|
||||
{
|
||||
ActivePreset.CameraHolder.SetActive(false);
|
||||
|
||||
@@ -13,49 +13,42 @@ public class GameController :MonoBehaviour
|
||||
[SerializeField] UnityEngine.UI.Button NextCarButton;
|
||||
public static GameController Instance;
|
||||
public GameObject PlayerCar;
|
||||
public GameObject cam;
|
||||
public static bool RaceIsStarted { get { return true; } }
|
||||
public static bool RaceIsEnded { get { return false; } }
|
||||
|
||||
PlayerController m_PlayerCar;
|
||||
List<PlayerController> Cars = new List<PlayerController>();
|
||||
//PlayerController m_PlayerCar;
|
||||
//List<PlayerController> Cars = new List<PlayerController>();
|
||||
public List<GameObject> cars;
|
||||
int CurrentCarIndex = 0;
|
||||
|
||||
protected virtual void Awake ()
|
||||
{
|
||||
|
||||
|
||||
Instance = this;
|
||||
|
||||
//Find all cars in current game.
|
||||
Cars.AddRange (GameObject.FindObjectsOfType<PlayerController> ());
|
||||
Cars = Cars.OrderBy (c => c.name).ToList();
|
||||
// foreach (var car in cars)
|
||||
// {
|
||||
// var userControl = car.GetComponent<PlayerController>();
|
||||
// var audioListener = car.GetComponent<AudioListener>();
|
||||
|
||||
foreach (var car in Cars)
|
||||
{
|
||||
var userControl = car.GetComponent<PlayerController>();
|
||||
var audioListener = car.GetComponent<AudioListener>();
|
||||
// if (userControl == null)
|
||||
// {
|
||||
// userControl = car.gameObject.AddComponent<PlayerController> ();
|
||||
// }
|
||||
|
||||
if (userControl == null)
|
||||
{
|
||||
userControl = car.gameObject.AddComponent<PlayerController> ();
|
||||
}
|
||||
// if (audioListener == null)
|
||||
// {
|
||||
// audioListener = car.gameObject.AddComponent<AudioListener> ();
|
||||
// }
|
||||
|
||||
if (audioListener == null)
|
||||
{
|
||||
audioListener = car.gameObject.AddComponent<AudioListener> ();
|
||||
}
|
||||
// userControl.enabled = false;
|
||||
// audioListener.enabled = false;
|
||||
// }
|
||||
|
||||
userControl.enabled = false;
|
||||
audioListener.enabled = false;
|
||||
}
|
||||
|
||||
m_PlayerCar = Cars[0];
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
|
||||
if (NextCarButton)
|
||||
{
|
||||
NextCarButton.onClick.AddListener (NextCar);
|
||||
}
|
||||
|
||||
// cars[CurrentCarIndex].GetComponent<PlayerController>().enabled = true;
|
||||
// cars[CurrentCarIndex].GetComponent<AudioListener>().enabled = true;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
@@ -69,14 +62,20 @@ public class GameController :MonoBehaviour
|
||||
|
||||
private void NextCar ()
|
||||
{
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = false;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = false;
|
||||
// cars[CurrentCarIndex].GetComponent<PlayerController> ().enabled = false;
|
||||
// cars[CurrentCarIndex].GetComponent<AudioListener> ().enabled = false;
|
||||
|
||||
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, Cars.Count);
|
||||
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, cars.Count);
|
||||
|
||||
m_PlayerCar = Cars[CurrentCarIndex];
|
||||
m_PlayerCar.GetComponent<PlayerController> ().enabled = true;
|
||||
m_PlayerCar.GetComponent<AudioListener> ().enabled = true;
|
||||
// cars[CurrentCarIndex].GetComponent<PlayerController>().enabled = true;
|
||||
// cars[CurrentCarIndex].GetComponent<AudioListener>().enabled = true;
|
||||
|
||||
PlayerCar = cars[CurrentCarIndex];
|
||||
|
||||
cam.GetComponent<CameraControl>().getCar(PlayerCar);
|
||||
|
||||
|
||||
print(PlayerCar.name);
|
||||
}
|
||||
|
||||
public static int LoopClamp (int value, int minValue, int maxValue)
|
||||
|
||||
Reference in New Issue
Block a user