-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameManager.cs
86 lines (75 loc) · 2.26 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
public int level=1;
public int food=10;
//public Text textLevel;
public Image dayImage;
public Text dayText;
public Text textFood;
public Player player;
private MapManager mapManager;
private Loader firstStart;
private static GameManager _instance;
public static GameManager Instance {
get {
return _instance;
}
}
// Use this for initialization
void Awake() {
_instance = this;
if (level == 0)
{
level += 1;
food += 10;
}
else
{
level = PlayerPrefs.GetInt("level");
food = PlayerPrefs.GetInt("food");
}
mapManager = this.GetComponent<MapManager>();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
textFood = GameObject.FindGameObjectWithTag("FoodText").GetComponent<Text>();
dayImage = GameObject.Find("dayImage").GetComponent<Image>();
dayText = GameObject.Find("dayText").GetComponent<Text>();
//textLevel = GameObject.FindGameObjectWithTag("LevelText").GetComponent<Text>();
//此处需要改。游戏是否继承
dayText.text = "DAY " + level;
Invoke("HideBlack",1);
ShowText();
}
void ShowText() {
textFood.text = "Food : "+ food;
}
public void Update()
{
GameOver();
}
public void exitOut() {
level += 1;
PlayerPrefs.SetInt("level", level);
PlayerPrefs.SetInt("food", food);
SceneManager.LoadScene("Main");
}
public void AddFood(int count){
food += count;
textFood.text = "+" + count + " Food: " + food;
}
public void ReduceFood(int count) {
food -= count;
textFood.text = "-" + count + " Food: " + food;
}
private void GameOver() {
if (food <= 0) {
SceneManager.LoadScene("GameOver");
}
}
void HideBlack() {
dayImage.gameObject.SetActive(false);
}
}