using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; public class HUDManager : MonoBehaviour { public GameObject[] highScores; public Text[] chronos; public Text[] firsts; public Text[] tachometers; public Text[] maxSpeeds; public HUDProgress[] progressions; public Text[] distances; [SerializeField] private GameObject[] _messages; public GameObject[] Messages {get {return _messages;} } public GameObject loadingScreens; public float[] maxSpeedsValues = new float[2]; GameManager gm; void Awake() { gm = GameManager.Instance; gm.RegisterHUD(this); } // Use this for initialization void Start () { } // Update is called once per frame void Update () { UpdateSpeeds(0); UpdateProgress(0); UpdateDistance(0); UpdateChrono (0); UpdateFirst (0); } void UpdateFirst(int bikeID) { firsts [bikeID].text = (gm.GetFirst () + 1).ToString(); } void UpdateChrono(int bikeID) { float time = gm.GetChrono (); TimeSpan timeSpan = TimeSpan.FromSeconds(time); chronos [bikeID].text = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds / 10); } void UpdateDistance(int bikeID) { distances[bikeID].text = gm.GetBikeManager(bikeID).GetDistance().ToString("#0") + "m"; } void UpdateProgress(int bikeID) { progressions[bikeID].SetProgress(gm.GetBikeManager(bikeID).GetProgress()); } void UpdateSpeeds(int bikeID) { float s = gm.GetBikeManager(bikeID).GetSpeed(); if (s > maxSpeedsValues[bikeID]) maxSpeedsValues[bikeID] = s; tachometers[bikeID].text = (s * 3.6f).ToString("#0.0") + "km/h"; maxSpeeds[bikeID].text = "Max : " + (maxSpeedsValues[bikeID] * 3.6f).ToString("#0.0"); } public void SetMessageActive(bool status, int playerID=2) { if (playerID > 1) { Messages [0].SetActive (status); // Messages[1].SetActive(status); } else { Messages [playerID].SetActive (status); } } public void SetMessage(string message, int playerID=2) { if (playerID > 1) { Messages [0].GetComponent ().text = message; // Messages[1].GetComponent().text = message; } else { Messages [playerID].GetComponent ().text = message; } } public void SetHighScore(int playerID) { highScores [playerID].SetActive (true); } }