Lade till knappar efter det att spelet är klart
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
public class BallController : MonoBehaviour {
|
||||
|
||||
[SerializeField] private TMP_Text _pickupLeftText;
|
||||
[SerializeField] private TMP_Text _timeSpentText;
|
||||
[SerializeField] private TMP_Text _winText;
|
||||
[SerializeField] Button _playAgain;
|
||||
[SerializeField] Button _quit;
|
||||
int _pickupLeft;
|
||||
float _ballSpeed;
|
||||
float _brakeForce;
|
||||
float _jumpForce;
|
||||
@@ -13,15 +22,35 @@ public class BallController : MonoBehaviour {
|
||||
_ballSpeed = 3f;
|
||||
_brakeForce = 0.3f;
|
||||
_jumpForce = 14f;
|
||||
_pickupLeft = GameObject.FindGameObjectsWithTag("PickUp").Length;
|
||||
transform.position = new Vector3(0, 0.5f, 0);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
KeyHandler();
|
||||
CheckPlayerOut();
|
||||
UpdateGUI();
|
||||
}
|
||||
|
||||
void UpdateGUI() {
|
||||
_pickupLeftText.text = "Left: " + _pickupLeft.ToString();
|
||||
_timeSpentText.text = "Tid: " + Time.timeSinceLevelLoad.ToString("F1") + "s";
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other) {
|
||||
other.gameObject.SetActive(false);
|
||||
_pickupLeft--;
|
||||
if (_pickupLeft == 0)
|
||||
LevelDone();
|
||||
}
|
||||
|
||||
void LevelDone() {
|
||||
_pickupLeftText.gameObject.SetActive(false);
|
||||
_timeSpentText.gameObject.SetActive(false);
|
||||
_winText.text = "Snyggt jobbat!\nDin tid: " + Time.timeSinceLevelLoad.ToString("F1") + "s";
|
||||
_winText.gameObject.SetActive(true);
|
||||
_playAgain.gameObject.SetActive(true);
|
||||
_quit.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
void CheckPlayerOut() {
|
||||
|
||||
Reference in New Issue
Block a user