Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using System.Linq;
- public class GameStateManager : MonoBehaviour {
- public GameObject[] pauseObjects;
- private bool _isPaused;
- public Image soundImage;
- public Sprite muteSprite;
- public Sprite unmuteSprite;
- private bool _isPlaying = false;
- public AudioSource audioGamePlay;
- public Image pauseSnakeHead;
- private List<SnakeSection> _tail;
- public SnakeSection section1;
- public SnakeSection section2;
- public SnakeSection section3;
- public SnakeSection section4;
- public SnakeSection section5;
- public SnakeSection section6;
- public SnakeSection section7;
- public SnakeSection section8;
- public SnakeSection section9;
- public SnakeSection section10;
- public SnakeSection section11;
- // Use this for initialization
- void Start () {
- Time.timeScale = 1;
- pauseObjects = GameObject.FindGameObjectsWithTag("ShowOnPause");
- HidePaused();
- _isPaused = false;
- soundImage.sprite = unmuteSprite;
- audioGamePlay = GetComponent<AudioSource>();
- audioGamePlay.Play(0);
- pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 0);
- _tail = new List<SnakeSection>();
- _tail.Add(section1);
- _tail.Add(section2);
- _tail.Add(section3);
- _tail.Add(section4);
- _tail.Add(section5);
- _tail.Add(section6);
- _tail.Add(section7);
- _tail.Add(section8);
- _tail.Add(section9);
- _tail.Add(section10);
- _tail.Add(section11);
- }
- IEnumerator Movement()
- {
- while (true)
- {
- //Move();
- yield return new WaitForSeconds(0.8f);
- Debug.Log("Some action");
- }
- }
- void Move()
- {
- Vector2 currentPosition = pauseSnakeHead.transform.position;
- if (pauseSnakeHead.transform.position.x == 220 && pauseSnakeHead.transform.position.y == 167)
- {
- pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 90);
- }
- else if (pauseSnakeHead.transform.position.x == -260 && pauseSnakeHead.transform.position.y == 167)
- {
- pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 180);
- }
- else if (pauseSnakeHead.transform.position.x == -260 && pauseSnakeHead.transform.position.y == -163)
- {
- pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 270);
- }
- else if (pauseSnakeHead.transform.position.x == 220 && pauseSnakeHead.transform.position.y == -163)
- {
- pauseSnakeHead.transform.rotation = Quaternion.Euler(0, 0, 0);
- }
- pauseSnakeHead.transform.Translate(0, 30, 0);
- _tail.Last().transform.position = currentPosition;
- _tail.Insert(0, _tail.Last());
- _tail.RemoveAt(_tail.Count - 1);
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyUp(KeyCode.P))
- {
- if (Time.timeScale == 1)
- {
- Time.timeScale = 0;
- ShowPaused();
- StartCoroutine(Movement());
- }
- else if (Time.timeScale == 0)
- {
- Time.timeScale = 1;
- HidePaused();
- }
- }
- if (Input.GetKeyUp(KeyCode.M))
- {
- if (_isPlaying)
- {
- audioGamePlay.Pause();
- soundImage.sprite = muteSprite;
- }
- else
- {
- audioGamePlay.UnPause();
- soundImage.sprite = unmuteSprite;
- }
- _isPlaying = !_isPlaying;
- }
- }
- public bool isPaused() {
- return _isPaused;
- }
- public void ShowPaused()
- {
- foreach (GameObject gameObject in pauseObjects)
- {
- gameObject.SetActive(true);
- }
- _isPaused = true;
- audioGamePlay.Pause();
- }
- public void HidePaused()
- {
- foreach (GameObject gameObject in pauseObjects)
- {
- gameObject.SetActive(false);
- }
- _isPaused = false;
- audioGamePlay.UnPause();
- }
- public void ResumeGame() {
- Time.timeScale = 1;
- HidePaused();
- }
- public void StartGame()
- {
- SceneManager.LoadScene("GamePlay");
- }
- public void ExitGame()
- {
- SceneManager.LoadScene("MainMenu");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement