Merge branch 'master' of ooftooft.net:Racesm
# Conflicts: # Assets/ML-Agents/Timers/Car Customization_timers.json # Assets/ML-Agents/Timers/CityRacetrack_timers.json
This commit is contained in:
@@ -17,58 +17,44 @@ public class GameController :MonoBehaviour
|
||||
public static bool RaceIsStarted { get { return true; } }
|
||||
public static bool RaceIsEnded { get { return false; } }
|
||||
|
||||
//PlayerController m_PlayerCar;
|
||||
//List<PlayerController> Cars = new List<PlayerController>();
|
||||
public List<GameObject> cars;
|
||||
int CurrentCarIndex = 0;
|
||||
|
||||
protected virtual void Awake ()
|
||||
|
||||
private List<string> finished;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
Instance = this;
|
||||
|
||||
// foreach (var car in cars)
|
||||
// {
|
||||
// var userControl = car.GetComponent<PlayerController>();
|
||||
// var audioListener = car.GetComponent<AudioListener>();
|
||||
|
||||
// if (userControl == null)
|
||||
// {
|
||||
// userControl = car.gameObject.AddComponent<PlayerController> ();
|
||||
// }
|
||||
|
||||
// if (audioListener == null)
|
||||
// {
|
||||
// audioListener = car.gameObject.AddComponent<AudioListener> ();
|
||||
// }
|
||||
|
||||
// userControl.enabled = false;
|
||||
// audioListener.enabled = false;
|
||||
// }
|
||||
finished=gameObject.GetComponent<GameManager>().playersFinished;
|
||||
|
||||
|
||||
// cars[CurrentCarIndex].GetComponent<PlayerController>().enabled = true;
|
||||
// cars[CurrentCarIndex].GetComponent<AudioListener>().enabled = true;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
public void Update ()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown (NextCarKey))
|
||||
{
|
||||
NextCar ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void NextCar ()
|
||||
public void NextCar()
|
||||
{
|
||||
// cars[CurrentCarIndex].GetComponent<PlayerController> ().enabled = false;
|
||||
// cars[CurrentCarIndex].GetComponent<AudioListener> ().enabled = false;
|
||||
for (int i = 0; i < cars.Count; i++)
|
||||
{
|
||||
if (finished.Contains(cars[i].name))
|
||||
{
|
||||
cars.Remove(cars[i]);
|
||||
}
|
||||
}
|
||||
|
||||
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, cars.Count);
|
||||
|
||||
// cars[CurrentCarIndex].GetComponent<PlayerController>().enabled = true;
|
||||
// cars[CurrentCarIndex].GetComponent<AudioListener>().enabled = true;
|
||||
|
||||
|
||||
|
||||
PlayerCar = cars[CurrentCarIndex];
|
||||
|
||||
@@ -90,4 +76,6 @@ public class GameController :MonoBehaviour
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using UnityEditor.SearchService;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public int lapAmount;
|
||||
@@ -20,8 +21,13 @@ public class GameManager : MonoBehaviour
|
||||
public TextMeshProUGUI lapCounter;
|
||||
public TextMeshProUGUI timeCounter;
|
||||
public TextMeshProUGUI startTime;
|
||||
public TextMeshProUGUI DNFTime;
|
||||
public TextMeshProUGUI speedometer;
|
||||
public GameObject nextCarbtn;
|
||||
float DNFTimer = 0;
|
||||
private bool hasCountedDown = false;
|
||||
|
||||
private Rigidbody carRB;
|
||||
void Start()
|
||||
{
|
||||
AudioSource backgroundMusic = GameObject.Find("Car Data").GetComponent<AudioSource>();
|
||||
@@ -54,6 +60,10 @@ public class GameManager : MonoBehaviour
|
||||
StartGame();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < players.Count(); i++)
|
||||
{
|
||||
GameObject player = players[i];
|
||||
@@ -88,6 +98,9 @@ public class GameManager : MonoBehaviour
|
||||
else
|
||||
{
|
||||
int checkpointsCollected = player.GetComponent<PlayerController>().checkpointsCollected;
|
||||
carRB = player.GetComponent<Rigidbody>();
|
||||
var carVel = Mathf.Round((Mathf.Abs(carRB.velocity.x) + Mathf.Abs(carRB.velocity.y) + Mathf.Abs(carRB.velocity.z))*6);
|
||||
speedometer.SetText(carVel.ToString());
|
||||
|
||||
if (checkpointsCollected == checkpoints.Count())
|
||||
{
|
||||
@@ -99,18 +112,7 @@ public class GameManager : MonoBehaviour
|
||||
lapCounter.text = "Lap count: " + playerLaps[i] + "/" + lapAmount;
|
||||
}
|
||||
|
||||
string strTimes =playerTimes[i].ToString();
|
||||
|
||||
int seconds = (int)MathF.Floor(playerTimes[i]);
|
||||
int seperator = strTimes.IndexOf(",");
|
||||
string miliseconds;
|
||||
|
||||
if (strTimes.Length < seperator + 4)
|
||||
miliseconds = ",000";
|
||||
else
|
||||
miliseconds = strTimes.Substring(seperator, 4);
|
||||
|
||||
timeCounter.text = "Time: " + seconds + miliseconds;
|
||||
timeCounter.text = "Time: " + (Mathf.Round(playerTimes[i]*1000)/1000).ToString();
|
||||
}
|
||||
|
||||
if (playerLaps[i] > lapAmount)
|
||||
@@ -123,6 +125,7 @@ public class GameManager : MonoBehaviour
|
||||
else
|
||||
playersFinished.Add(player.name + " (player)");
|
||||
player.GetComponent<PlayerController>().enabled = false;
|
||||
nextCarbtn.SetActive(true);
|
||||
|
||||
playerTimesStr[i] = playerTimes[i].ToString();
|
||||
}
|
||||
@@ -134,6 +137,7 @@ public class GameManager : MonoBehaviour
|
||||
if (playersFinished.Count() > 0)
|
||||
{
|
||||
DNFTimer += Time.deltaTime;
|
||||
DNFTime.text = "DNF timer: "+(Mathf.Round(60-DNFTimer)).ToString();
|
||||
}
|
||||
|
||||
// race finished
|
||||
|
||||
Reference in New Issue
Block a user