PauseMenu.cs 1.99 KB
Newer Older
Isa's avatar
Isa committed
1
2
3
4
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
Isa's avatar
Isa committed
5
using UnityEngine.SceneManagement;
Isa's avatar
Isa committed
6
using UnityEngine.UI;
Isa's avatar
HUD    
Isa committed
7
using LevelauswahlScript;
Isa's avatar
Isa committed
8
9
10

public class PauseMenu : MonoBehaviour
{
Isa's avatar
Isa committed
11
12
	public GameObject pauseMenu;
	public EventSystem _myEventSystem;
Isa's avatar
Isa committed
13
	public Button firstSelect;
Isa's avatar
Isa committed
14
15
	private bool isPaused = false;
	private GameObject _old, _new;
Isa's avatar
Isa committed
16
	public GameObject HUD;
Isa's avatar
Isa committed
17
18
19
    // Start is called before the first frame update
    void Start()
    {
Isa's avatar
Isa committed
20

Isa's avatar
Isa committed
21
22
23
24
25
26
27
28
29
30
31
32
33
    }

    IEnumerator highlightBtn()
    {
	    _myEventSystem.SetSelectedGameObject(null);
	    yield return null;
	    _myEventSystem.firstSelectedGameObject = firstSelect.gameObject;
	    _myEventSystem.SetSelectedGameObject(_myEventSystem.firstSelectedGameObject);
    }

    // Update is called once per frame
    void Update()
    {
Isa's avatar
Isa committed
34
35
36
37
38
	    _new = _myEventSystem.currentSelectedGameObject;
	    if (_new != null)
	    {
		    _old = _new;
	    }
Isa's avatar
Isa committed
39
        if(Input.GetButtonDown ("Cancel") && isPaused == true)
Isa's avatar
Isa committed
40
41
        {
	        Resume();
Isa's avatar
Isa committed
42
        } else if (Input.GetButtonDown ("Cancel") && isPaused == false && Levelauswahl.la.auswahlIsActive() == false)
Isa's avatar
Isa committed
43
44
45
        {
	        Pause();
        }
Isa's avatar
Isa committed
46
        if (Input.GetMouseButtonDown(0))
Isa's avatar
Isa committed
47
48
49
        {
	        _myEventSystem.SetSelectedGameObject(_old);
        }
Isa's avatar
Isa committed
50
51
    }

Isa's avatar
Isa committed
52
53
54
55
56
    public void selectBtn(Button optionBtn)
    {
	    optionBtn.Select();
    }

Isa's avatar
Isa committed
57
58
59
60
61
    public void Resume()
    {
	    isPaused = false;
	    pauseMenu.SetActive(false);
	    Time.timeScale = 1f;
Isa's avatar
Isa committed
62
	    HUD.SetActive(true);
Isa's avatar
Isa committed
63
64
65
66
    }

    public void Pause()
    {
Isa's avatar
Isa committed
67
	    Time.timeScale = 0f;
Isa's avatar
Isa committed
68
69
70
	    isPaused = true;
	    pauseMenu.SetActive(true);
	    StartCoroutine("highlightBtn");
Isa's avatar
Isa committed
71
	    HUD.SetActive(false);
Isa's avatar
Isa committed
72
    }
Isa's avatar
Isa committed
73
74
75
76
77
78
79
80
81
82

    public void SwitchToMouse()
    {
    	_myEventSystem.GetComponent<UnityEngine.EventSystems.EventSystem>().SetSelectedGameObject(null);
    }

    public void LoadMenu()
    {
	    SceneManager.LoadScene("MainMenu");
    }
Isa's avatar
Isa committed
83
84
85
86
87

    public void LoadGame()
    {
	    SceneManager.LoadScene("MainLevel");
    }
Isa's avatar
Isa committed
88
}