MainMenu.cs 1.48 KB
Newer Older
1
using System.Collections;
Isa's avatar
Isa committed
2
3
4
5
6
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
Isa's avatar
Isa committed
7
8
using PlayerSpawnPointScript;
using UnityEngine.SceneManagement;
Isa's avatar
Isa committed
9
10
11

public class MainMenu : MonoBehaviour
{
12
	public StartPointObject startPointObject;
Isa's avatar
Isa committed
13
14
15
16
17
	private EventSystem _myEventSystem;
	private GameObject _backScreen, _currentScreen;
	private Button _selectedBtn;
	private GameObject _old, _new;

18

Isa's avatar
Isa committed
19
20
21
22
23
24
25
26
27
28
29
30
	void Start()
	{
		_myEventSystem = EventSystem.current;
	}

	void Update()
	{
		_new = _myEventSystem.currentSelectedGameObject;
		if (_new != null)
		{
			_old = _new;
		}
Isa's avatar
Isa committed
31
		if(Input.GetButtonDown ("Cancel") && _backScreen != null)
Isa's avatar
Isa committed
32
33
34
35
36
37
38
39
40
41
42
43
44
		{
			_backScreen.SetActive(true);
			_currentScreen.SetActive(false);
			_selectedBtn.Select();
			_backScreen = null;
		}

		if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
		{
			_myEventSystem.SetSelectedGameObject(_old);
		}
	}

Isa's avatar
Isa committed
45
	public void NewGame()
Isa's avatar
Isa committed
46
	{
47
		SceneManager.LoadScene("MainLevel");
48
		SaveSystem.NewGame(startPointObject.startPoint.position);
Isa's avatar
Isa committed
49
50
	}

51
52
	public void LoadGame()
	{
53
		SceneManager.LoadScene("MainLevel");
54
55
	}

Isa's avatar
Isa committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	public void SwitchToMouse()
	{
		_myEventSystem.GetComponent<UnityEngine.EventSystems.EventSystem>().SetSelectedGameObject(null);
	}

	public void SetBackScreen(GameObject bScreen)
	{
		_backScreen = bScreen;
	}

	public void SetCurrentScreen(GameObject cScreen)
	{
		_currentScreen = cScreen;
	}

	public void SelectBtn(Button btn)
	{
		_selectedBtn = btn;
	}
}