void OnGUI() { bold_style.normal.textColor = new Color(1, 0, 0); bold_style.fontSize = 16; text_style.normal.textColor = new Color(0, 0, 0, 1); text_style.fontSize = 16; score_style.normal.textColor = new Color(1, 0, 1, 1); score_style.fontSize = 16; over_style.normal.textColor = new Color(1, 0, 0); over_style.fontSize = 25; if (!game_start) { GUI.Label(new Rect(Screen.width / 2 - 30, Screen.width / 2 - 350, 100, 100), "HelloUFO!", over_style); GUI.Label(new Rect(Screen.width / 2 - 150, Screen.width / 2 - 220, 400, 100), "大量UFO出现,点击它们,即可消灭,快来加入战斗吧", text_style); if (GUI.Button(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 150, 100, 50), "游戏开始")) { Debug.Log(game_start); game_start = true; action.BeginGame(); } } else { //用户射击 if (Input.GetButtonDown("Fire1")) { Vector3 pos = Input.mousePosition; Debug.Log("right here userGUI 1"); action.Hit(pos); } GUI.Label(new Rect(10, 5, 200, 50), "分数:", text_style); GUI.Label(new Rect(55, 5, 200, 50), action.GetScore().ToString(), score_style); GUI.Label(new Rect(Screen.width - 120, 5, 50, 50), "生命:", text_style); //显示当前血量 for (int i = 0; i < life; i++) { GUI.Label(new Rect(Screen.width - 75 + 10 * i, 5, 50, 50), "X", bold_style); } //游戏结束 if (life == 0) { high_score = high_score > action.GetScore() ? high_score : action.GetScore(); GUI.Label(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 250, 100, 100), "游戏结束", over_style); GUI.Label(new Rect(Screen.width / 2 - 10, Screen.width / 2 - 200, 50, 50), "最高分:", text_style); GUI.Label(new Rect(Screen.width / 2 + 50, Screen.width / 2 - 200, 50, 50), high_score.ToString(), text_style); if (GUI.Button(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 150, 100, 50), "重新开始")) { life = 6; action.ReStart(); return; } action.GameOver(); } } }
// Update is called once per frame void OnGUI() { bold_style.normal.textColor = new Color(1, 0, 0); bold_style.fontSize = 16; text_style.normal.textColor = new Color(0, 0, 0, 1); text_style.fontSize = 16; score_style.normal.textColor = new Color(1, 0, 1, 1); score_style.fontSize = 16; over_style.normal.textColor = new Color(1, 0, 0); over_style.fontSize = 25; if (!game_start) { GUI.Label(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 320, 400, 100), "你的孩子被乌鸦抓走了!快去拯救它吧!", text_style); if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 250, 100, 50), "游戏开始")) { Debug.Log(game_start); game_start = true; action.BeginGame(); } } else { GUI.Label(new Rect(10, 5, 200, 50), "分数:", text_style); GUI.Label(new Rect(55, 5, 200, 50), action.GetScore().ToString(), score_style); //游戏结束 if (action.IfGameOver()) { GUI.Label(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 250, 100, 100), "游戏结束", over_style); if (GUI.Button(new Rect(Screen.width / 2 - 20, Screen.width / 2 - 150, 100, 50), "重新开始")) { action.ReStart(); return; } action.GameOver(); } } }