-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.cs
54 lines (46 loc) · 1.42 KB
/
Home.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Home : MonoBehaviour {
public string GameName = "UFO 2.0";
public string HowToPlayScene = "How_To_Play";
public string GameScene = "Game";
public AudioClip menuMusic;
private Canvas canvas;
private LevelManager levelManager;
private MusicManager musicManager;
private AudioSource homeAudioSource;
public AudioClip buttonPressSound;
void Awake() {
homeAudioSource = gameObject.AddComponent<AudioSource> () as AudioSource;
homeAudioSource.clip = buttonPressSound;
canvas = FindObjectOfType<Canvas> ();
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;
musicManager.SetBackgroundMusic (menuMusic);
musicManager.Play ();
}
DontDestroyOnLoad (levelManager);
DontDestroyOnLoad (musicManager);
}
public void TransitionHowTo() {
homeAudioSource.Play ();
Invoke ("LoadHowTo", 0.2f);
}
public void TransitionGame() {
homeAudioSource.Play ();
Invoke ("LoadGame", 0.2f);
}
private void LoadHowTo() {
levelManager.Load (HowToPlayScene);
}
private void LoadGame() {
levelManager.Load (GameScene);
}
}