-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameManager.cs
100 lines (82 loc) · 3.39 KB
/
GameManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public Vector3 playerStartPosition;
public bool increaseSpeedOfPlayer;
public GameObject crushClosingAnim;
public GameObject timeClosingAnim;
public GameObject timeText;
public GameObject player;
public GameObject circle;
// Start is called before the first frame update
void Awake()
{
player = (GameObject) Resources.Load("player/" + PlayerPrefs.GetString("selectedVehicle", "Tank"));
player.GetComponent<Rope>().segmentLength = 14 + PlayerPrefs.GetInt("circleSize", 10) / 20;
player.transform.position = playerStartPosition;
/**
if (increaseSpeedOfPlayer)
{
player.GetComponent<PlayerMovement>().speed += 1;
player.GetComponent<PlayerMovement>().rotationSpeed += 10;
}
*/
Instantiate(player);
circle = (GameObject) Resources.Load("circle/" + PlayerPrefs.GetString("selectedCircle", "Orange") );
circle.transform.localScale = new Vector3(PlayerPrefs.GetInt("circleSize", 10) / 40 + 2f, PlayerPrefs.GetInt("circleSize", 10) / 40 + 2f, 1);
Instantiate(circle);
}
public void GameOver()
{
crushClosingAnim.GetComponent<CrushClosingAnimation>().ShowScore();
crushClosingAnim.SetActive(true);
}
public void LoadFirstScene()
{
SceneManager.LoadScene(0);
}
public void RestartScene()
{
SceneManager.LoadScene( SceneManager.GetActiveScene().buildIndex);
if (PlayerPrefs.GetInt("MusicEnabled", 1) == 1 )
{
FindObjectOfType<AudioManager>().Pause("GameMusic");
FindObjectOfType<AudioManager>().Play("GameMusic2");
}
}
public void LoadNextLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
if (PlayerPrefs.GetInt("MusicEnabled", 1) == 1)
{
FindObjectOfType<AudioManager>().PauseWithFadeOut("GameMusic" , 0.5f);
FindObjectOfType<AudioManager>().PlayWithFadeIn("GameMusic2" , 1.5f);
}
}
public void ContinueMainLevel()
{
player = GameObject.FindGameObjectWithTag("Player");
circle = GameObject.FindGameObjectWithTag("Circle");
player.transform.position = playerStartPosition;
circle.transform.position = playerStartPosition - new Vector3(0, 5, 0);
player.transform.up = Vector2.up;
player.GetComponent<SpriteRenderer>().enabled = true;
player.GetComponent<Collider2D>().enabled = true;
circle.GetComponent<Collider2D>().enabled = true;
if (PlayerPrefs.GetInt("MusicEnabled", 1) == 1 )
{
FindObjectOfType<AudioManager>().Play("GameMusic2");
}
timeClosingAnim = GameObject.FindGameObjectWithTag("TimeClosingAnim");
if (timeClosingAnim != null) { timeClosingAnim.SetActive(false); };
if (crushClosingAnim != null) { crushClosingAnim.SetActive(false); };
timeText = GameObject.FindGameObjectWithTag("TimeText");
if( timeText != null)
{
timeText.GetComponent<MyTime>().setTimeLeft(timeText.GetComponent<MyTime>().timeLimit);
timeText.GetComponent<MyTime>().gameStoped = false;
};
}
}