-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
60 lines (51 loc) · 1.45 KB
/
Game.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Game : MonoBehaviour {
public ScoreBoard scoreBoard;
public GameObject ufo;
public bool gameOn = false;
public AudioClip gameBackgroundMusic;
private LevelManager levelManager;
private PlayerMovement playerMovement;
private MusicManager musicManager;
private Rigidbody rbd;
void Awake() {
scoreBoard = new GameObject ().AddComponent (typeof(ScoreBoard)) as ScoreBoard;
DontDestroyOnLoad (scoreBoard);
playerMovement = ufo.GetComponent<PlayerMovement> ();
levelManager = FindObjectOfType<LevelManager> ();
if (levelManager == null) {
levelManager = new GameObject ().AddComponent (typeof(LevelManager)) as LevelManager;
}
musicManager = FindObjectOfType<MusicManager> ();
if (musicManager == null) {
musicManager = new GameObject ().AddComponent (typeof(MusicManager)) as MusicManager;
}
playerMovement.canMove = false;
rbd = ufo.GetComponent<Rigidbody> ();
rbd.isKinematic = true;
}
void Start() {
musicManager.Stop ();
musicManager.SetBackgroundMusic (gameBackgroundMusic);
musicManager.Play ();
CountDown ();
}
void CountDown() {
//Show the countdown
Invoke ("StartGame", 2.0f);
}
void StartGame() {
playerMovement.canMove = true;
rbd.isKinematic = false;
gameOn = true;
}
public void GameOver () {
gameOn = false;
Invoke ("LoadGameOver", 2.0f);
}
void LoadGameOver() {
levelManager.Load ("Game_Over");
}
}