Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using TMPro;
- using UnityEngine;
- public class GameManager : MonoBehaviour
- {
- public Animator UIanimator;
- public Rigidbody[] ballRBs;
- public TMP_Text timeScaleText;
- public TMP_Text countdownText;
- private bool uiOpen = false;
- private bool inCountdown = false;
- private int countdownSecond = 0;
- // Update is called once per frame
- private void Start()
- {
- countdownText.text = "";
- }
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- if (!uiOpen && !inCountdown)
- PauseFunction();
- else if (uiOpen && !inCountdown)
- ResumeFunction();
- }
- if (Input.GetKeyDown(KeyCode.F))
- {
- if (!uiOpen && !inCountdown)
- AddForceToBalls();
- }
- timeScaleText.text = "TimeScale: "+Time.timeScale;
- }
- private void AddForceToBalls()
- {
- foreach (Rigidbody rb in ballRBs)
- {
- rb.AddForce(rb.transform.up * 100f *Random.Range(2,5));
- }
- }
- private void PauseFunction()
- {
- Time.timeScale = 0;
- uiOpen = true;
- UIanimator.SetBool("openUI", uiOpen);
- }
- private IEnumerator ResumeGame()
- {
- uiOpen = false;
- UIanimator.SetBool("openUI", uiOpen);
- inCountdown = true;
- countdownSecond = 3;
- while (countdownSecond > 0 )
- {
- countdownText.text = countdownSecond.ToString();
- countdownSecond--;
- yield return new WaitForSecondsRealtime(1f);
- }
- inCountdown = false;
- countdownText.text = "";
- Time.timeScale = 1;
- }
- public void ResumeFunction()
- {
- StartCoroutine(ResumeGame());
- }
- }
Add Comment
Please, Sign In to add comment