Advertisement
forestfoxy

Untitled

Jul 27th, 2018
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. using System.Linq;
  7.  
  8. public class GameStateManager : MonoBehaviour {
  9.     public GameObject[] pauseObjects;
  10.     private bool _isPaused;
  11.     public Image soundImage;
  12.     public Sprite muteSprite;
  13.     public Sprite unmuteSprite;
  14.     private bool _isPlaying = false;
  15.     public AudioSource audioGamePlay;
  16.  
  17.     public Image pauseSnakeHead;
  18.     private List<SnakeSection> _tail;
  19.     public SnakeSection section1;
  20.     public SnakeSection section2;
  21.     public SnakeSection section3;
  22.     public SnakeSection section4;
  23.     public SnakeSection section5;
  24.     public SnakeSection section6;
  25.     public SnakeSection section7;
  26.     public SnakeSection section8;
  27.     public SnakeSection section9;
  28.     public SnakeSection section10;
  29.     public SnakeSection section11;
  30.  
  31.     // Use this for initialization
  32.     void Start () {
  33.         Time.timeScale = 1;
  34.         pauseObjects = GameObject.FindGameObjectsWithTag("ShowOnPause");
  35.         HidePaused();
  36.         _isPaused = false;
  37.         soundImage.sprite = unmuteSprite;
  38.         audioGamePlay = GetComponent<AudioSource>();
  39.         audioGamePlay.Play(0);
  40.         pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 0);
  41.         _tail = new List<SnakeSection>();
  42.         _tail.Add(section1);
  43.         _tail.Add(section2);
  44.         _tail.Add(section3);
  45.         _tail.Add(section4);
  46.         _tail.Add(section5);
  47.         _tail.Add(section6);
  48.         _tail.Add(section7);
  49.         _tail.Add(section8);
  50.         _tail.Add(section9);
  51.         _tail.Add(section10);
  52.         _tail.Add(section11);
  53.     }
  54.  
  55.     IEnumerator Movement()
  56.     {
  57.         while (true)
  58.         {
  59.             //Move();
  60.             yield return new WaitForSeconds(0.8f);
  61.             Debug.Log("Some action");
  62.         }
  63.     }
  64.  
  65.     void Move()
  66.     {
  67.         Vector2 currentPosition = pauseSnakeHead.transform.position;
  68.  
  69.         if (pauseSnakeHead.transform.position.x == 220 && pauseSnakeHead.transform.position.y == 167)
  70.         {
  71.             pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 90);
  72.         }
  73.         else if (pauseSnakeHead.transform.position.x == -260 && pauseSnakeHead.transform.position.y == 167)
  74.         {
  75.             pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 180);
  76.         }
  77.         else if (pauseSnakeHead.transform.position.x == -260 && pauseSnakeHead.transform.position.y == -163)
  78.         {
  79.             pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 270);
  80.         }
  81.         else if (pauseSnakeHead.transform.position.x == 220 && pauseSnakeHead.transform.position.y == -163)
  82.         {
  83.             pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 0);
  84.         }
  85.  
  86.         pauseSnakeHead.transform.Translate(0, 30, 0);
  87.  
  88.         _tail.Last().transform.position = currentPosition;
  89.         _tail.Insert(0, _tail.Last());
  90.         _tail.RemoveAt(_tail.Count - 1);
  91.     }
  92.    
  93.     // Update is called once per frame
  94.     void Update () {
  95.         if (Input.GetKeyUp(KeyCode.P))
  96.         {
  97.             if (Time.timeScale == 1)
  98.             {
  99.                 Time.timeScale = 0;
  100.                 ShowPaused();
  101.                 StartCoroutine(Movement());
  102.             }
  103.             else if (Time.timeScale == 0)
  104.             {
  105.                 Time.timeScale = 1;
  106.                 HidePaused();
  107.             }
  108.         }
  109.  
  110.         if (Input.GetKeyUp(KeyCode.M))
  111.         {
  112.             if (_isPlaying)
  113.             {
  114.                 audioGamePlay.Pause();
  115.                 soundImage.sprite = muteSprite;
  116.             }
  117.             else
  118.             {
  119.                 audioGamePlay.UnPause();
  120.                 soundImage.sprite = unmuteSprite;
  121.  
  122.             }
  123.             _isPlaying = !_isPlaying;
  124.         }
  125.     }
  126.  
  127.     public bool isPaused() {
  128.         return _isPaused;
  129.     }
  130.  
  131.     public void ShowPaused()
  132.     {
  133.         foreach (GameObject gameObject in pauseObjects)
  134.         {
  135.             gameObject.SetActive(true);
  136.         }
  137.         _isPaused = true;
  138.         audioGamePlay.Pause();
  139.     }
  140.  
  141.     public void HidePaused()
  142.     {
  143.         foreach (GameObject gameObject in pauseObjects)
  144.         {
  145.             gameObject.SetActive(false);
  146.         }
  147.         _isPaused = false;
  148.         audioGamePlay.UnPause();
  149.     }
  150.  
  151.     public void ResumeGame() {
  152.         Time.timeScale = 1;
  153.         HidePaused();
  154.     }
  155.  
  156.     public void StartGame()
  157.     {
  158.         SceneManager.LoadScene("GamePlay");
  159.     }
  160.  
  161.     public void ExitGame()
  162.     {
  163.         SceneManager.LoadScene("MainMenu");
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement