Skip to content

Commit

Permalink
feat: endgame ui buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
pyoneerC committed Sep 26, 2024
1 parent 8e042c7 commit 8ee86d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Assets/Scenes/Reparation.unity
Original file line number Diff line number Diff line change
Expand Up @@ -15795,7 +15795,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 240, y: -310}
m_AnchoredPosition: {x: 271, y: -310}
m_SizeDelta: {x: 200, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &754738739
Expand Down Expand Up @@ -24749,6 +24749,8 @@ MonoBehaviour:
oxygenWarningsAmountText: {fileID: 474630863}
distanceCoveredText: {fileID: 16681213}
reticle: {fileID: 1374808373}
restartButton: {fileID: 1480355432}
quitButton: {fileID: 931267296}
--- !u!4 &1130256303 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -5819118886272102141, guid: e0f672a015f8fee418afd70dfd718f0d, type: 3}
Expand Down Expand Up @@ -36921,7 +36923,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -360, y: -380}
m_AnchoredPosition: {x: -300, y: -400}
m_SizeDelta: {x: 200, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1634647095
Expand Down
16 changes: 15 additions & 1 deletion Assets/Scripts/UI/Endgame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Endgame : MonoBehaviour
public TextMeshProUGUI oxygenWarningsAmountText; // Number of times an oxygen warning was triggered
public TextMeshProUGUI distanceCoveredText; // Distance covered as the sum of all 3 components (x, y, z)
public Image reticle;
public Button restartButton;
public Button quitButton;

private Health _health; // Reference to player health
private FixLogic _fixLogic; // Reference to the fixing logic
Expand Down Expand Up @@ -54,6 +56,14 @@ private void Start()
// Initialize the text elements to be transparent (not visible)
SetTextVisibility(false);

//hide buttons
restartButton.gameObject.SetActive(false);
quitButton.gameObject.SetActive(false);

//bind buttons
restartButton.onClick.AddListener(() => { UnityEngine.SceneManagement.SceneManager.LoadScene(0); });
quitButton.onClick.AddListener(Application.Quit);

// Start time tracking
_timePlayed = Time.time;

Expand Down Expand Up @@ -92,8 +102,8 @@ private void EndGame(bool isVictory)
if (isVictory)
{
_score = Random.Range(7, 11); // Random score between 7 and 10
endgameText.text = "Felicidades!"; // Victory message
endgameText.color = Color.green; // Change text color to green
endgameText.text = "Felicidades!"; // Victory message
}
else
{
Expand All @@ -117,6 +127,10 @@ private void UpdateUI()
timePerPipeText.text = $"{_timePlayed / 7:F2} s";
oxygenWarningsAmountText.text = $"{_oxygenAlertsCount}";
distanceCoveredText.text = $"{Vector3.Distance(_startPosition, _playerTransform.position):F2} m";

// Show buttons
restartButton.gameObject.SetActive(true);
quitButton.gameObject.SetActive(true);
}

private void SetTextVisibility(bool visible)
Expand Down

0 comments on commit 8ee86d1

Please sign in to comment.