73 lines
1.9 KiB
C#

using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
public class UIManager : MonoBehaviour
{
[SerializeField]
Button startBtn;
[SerializeField]
Text speedTxt;
[SerializeField]
Text powerTxt;
[SerializeField]
Text timerTxt;
[SerializeField]
Text countDownTxt;
PlayerController playerController;
private float timeRemaining = 1f;
private int count = 0;
// Start is called before the first frame update
void Start()
{
startBtn.onClick.AddListener(StartRide);
}
private void StartRide()
{
playerController = transform.parent.Find("Player").GetComponent<PlayerController>();
//加个5秒钟倒计时
count = 5;
startBtn.gameObject.SetActive(false);
countDownTxt.gameObject.SetActive(true);
countDownTxt.text = count.ToString();
}
// Update is called once per frame
void Update()
{
if (playerController != null)
{
speedTxt.text = $"{playerController.Speed}";
powerTxt.text = $"{playerController.Power}";
timerTxt.text = Helper.FormatTicks(playerController.TotalTicks);
if (count > 0)
{
timeRemaining -= Time.deltaTime;
if (timeRemaining <= 0)//定时器
{
count--;
if (count == 0)
{
playerController.SetStart(true);
countDownTxt.gameObject.SetActive(false);
}
timeRemaining = 1.0f;
}
}
countDownTxt.text = count.ToString();
}
}
}
}