Advertisement
dimon-torchila

Untitled

May 15th, 2022
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class GameOver : MonoBehaviour
  7. {
  8.  
  9.     [SerializeField]
  10.     private GameObject _gameOver;
  11.  
  12.     [SerializeField]
  13.     private GameObject _text;
  14.  
  15.     private GameObject _player;
  16.  
  17.    
  18.  
  19.     void Start()
  20.     {
  21.         _player = GameObject.Find("Player");
  22.         StartCoroutine(IncreaseCanvas());
  23.     }
  24.  
  25.    
  26.  
  27.     public void Restart()
  28.     {
  29.         SceneManager.LoadScene("Game");
  30.         Time.timeScale = 1f;
  31.         Cursor.lockState = CursorLockMode.Locked;
  32.     }
  33.  
  34.     public void Menu()
  35.     {
  36.         SceneManager.LoadScene("MainMenu");
  37.         Time.timeScale = 1f;
  38.     }
  39.    
  40.     private IEnumerator IncreaseCanvas()
  41.     {
  42.         Moving _controller = _player.GetComponent<Moving>();
  43.         Animation _anim = _text.GetComponent<Animation>();
  44.         while (Mathf.Abs(_controller.speed) > 0.1f && _controller.fuel != 0f) { }
  45.  
  46.         _anim.Play();
  47.         yield return new WaitForSeconds(2f);
  48.         _gameOver.SetActive(true);
  49.         Time.timeScale = 0f;
  50.         Cursor.lockState = CursorLockMode.Confined;
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement