done
This commit is contained in:
parent
3a7ce962e7
commit
058e61a4fd
38 changed files with 3915 additions and 363 deletions
54
TP3/Assets/Scripts/UIThings/UIManager.cs
Normal file
54
TP3/Assets/Scripts/UIThings/UIManager.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
using UImage = UnityEngine.UI.Image;
|
||||
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] TextMeshProUGUI timeText;
|
||||
[SerializeField] TextMeshProUGUI velocityText;
|
||||
[SerializeField] TextMeshProUGUI lapText;
|
||||
[SerializeField] UImage boostBar;
|
||||
|
||||
[SerializeField] Rigidbody car;
|
||||
[SerializeField] Boost boost;
|
||||
[SerializeField] CheckpointCheck checkpointCheck;
|
||||
|
||||
bool has_won = false;
|
||||
float time = 0;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
int minute = (int) time / 60;
|
||||
int secondes = (int) time % 60;
|
||||
timeText.text = $"Time : {minute} min {secondes}s";
|
||||
|
||||
int velocity = (int) car.linearVelocity.magnitude;
|
||||
velocityText.text = $"{velocity} m/s";
|
||||
|
||||
boostBar.fillAmount = boost.charge;
|
||||
|
||||
lapText.text = $"Lap : {checkpointCheck.NumberOfLaps + 1} / {CheckpointCheck.MAX_LAPS}";
|
||||
|
||||
if (checkpointCheck.NumberOfLaps == CheckpointCheck.MAX_LAPS && !has_won)
|
||||
{
|
||||
Win();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Win()
|
||||
{
|
||||
has_won = true;
|
||||
EventBus.WinEvent.Invoke(time);
|
||||
}
|
||||
}
|
2
TP3/Assets/Scripts/UIThings/UIManager.cs.meta
Normal file
2
TP3/Assets/Scripts/UIThings/UIManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 377823b7918eb214598f5116386cfb1e
|
30
TP3/Assets/Scripts/UIThings/WinManager.cs
Normal file
30
TP3/Assets/Scripts/UIThings/WinManager.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class WinManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Canvas winCanvas;
|
||||
[SerializeField] Canvas uiCanvas;
|
||||
[SerializeField] TextMeshProUGUI scoreText;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
EventBus.WinEvent.AddListener(OnWin);
|
||||
}
|
||||
|
||||
void OnWin(float time)
|
||||
{
|
||||
uiCanvas.gameObject.SetActive(false);
|
||||
winCanvas.gameObject.SetActive(true);
|
||||
int minute = (int)time / 60;
|
||||
int secondes = (int)time % 60;
|
||||
scoreText.text = $"Time : {minute} min {secondes}s";
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
}
|
2
TP3/Assets/Scripts/UIThings/WinManager.cs.meta
Normal file
2
TP3/Assets/Scripts/UIThings/WinManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f3047ee8cef5064bbe5a10822558645
|
Loading…
Add table
Add a link
Reference in a new issue