void OnGUI() { GUIStyle textStyle = new GUIStyle(); GUIStyle buttonStyle = new GUIStyle(); textStyle.fontSize = 30; buttonStyle.fontSize = 15; if (start == 1) { if (GUI.Button(new Rect(Screen.width / 2 - 60, Screen.height / 2 + 150, 100, 30), "Start")) { chooseMode = 1; start = 0; } } if (chooseMode == 1) { if (GUI.Button(new Rect(Screen.width / 2 - 120, Screen.height / 2 + 150, 100, 30), "KINEMATIC")) { action.SetMode(ActionMode.KINEMATIC); action.BeginGame(); chooseMode = 0; } if (GUI.Button(new Rect(Screen.width / 2 - 0, Screen.height / 2 + 150, 100, 30), "PHYSICS")) { action.SetMode(ActionMode.PHYSICS); action.BeginGame(); chooseMode = 0; } } if (action.GetBlood() > 0) { GUI.Label(new Rect(10, 5, 200, 50), "回合:"); GUI.Label(new Rect(55, 5, 200, 50), action.GetRound().ToString()); GUI.Label(new Rect(10, 25, 200, 50), "分数:"); GUI.Label(new Rect(55, 25, 200, 50), action.GetScore().ToString()); GUI.Label(new Rect(10, 45, 200, 50), "血量:"); GUI.Label(new Rect(55, 45, 200, 50), action.GetBlood().ToString()); if (Input.GetButtonDown("Fire1")) { Vector3 pos = Input.mousePosition; action.hit(pos); Debug.Log("hit: " + pos); } } if (action.GetBlood() <= 0) { action.GameOver(); GUI.Label(new Rect(Screen.width / 2 - 60, Screen.height / 2 + 80, 100, 50), "You are dead!"); GUI.Label(new Rect(Screen.width / 2 - 60, Screen.height / 2 + 100, 100, 50), "Your score: "); GUI.Label(new Rect(Screen.width / 2 + 10, Screen.height / 2 + 100, 100, 50), action.GetScore().ToString()); if (GUI.Button(new Rect(Screen.width / 2 - 60, Screen.height / 2 + 190, 100, 30), "Restart")) { action.Restart(); start = 1; } } }
void OnGUI() { GUIStyle textStyle = new GUIStyle(); GUIStyle buttonStyle = new GUIStyle(); textStyle.fontSize = 30; buttonStyle.fontSize = 15; if (GUI.Button(new Rect(30, 50, 50, 30), "Start")) { action.BeginGame(); } if (action.GetBlood() > 0) { GUI.Label(new Rect(10, 10, 300, 150), "回合:"); GUI.Label(new Rect(50, 10, 300, 150), action.GetRound().ToString()); GUI.Label(new Rect(90, 10, 300, 150), "分数:"); GUI.Label(new Rect(130, 10, 300, 150), action.GetScore().ToString()); GUI.Label(new Rect(170, 10, 300, 150), "血量:"); GUI.Label(new Rect(210, 10, 300, 150), action.GetBlood().ToString()); if (Input.GetButtonDown("Fire1")) { Vector3 pos = Input.mousePosition; action.hit(pos); Debug.Log("hit: " + pos); } } if (action.GetBlood() <= 0) { action.GameOver(); GUI.Label(new Rect(Screen.width / 2 - 60, Screen.height / 2 + 80, 100, 50), "GameOver!"); GUI.Label(new Rect(Screen.width / 2 - 60, Screen.height / 2 + 100, 100, 50), "Your score: "); GUI.Label(new Rect(Screen.width / 2 + 10, Screen.height / 2 + 100, 100, 50), action.GetScore().ToString()); if (GUI.Button(new Rect(Screen.width / 2 - 60, Screen.height / 2, 100, 30), "Restart")) { action.Restart(); } } }
void OnGUI() { GUIStyle text_style; GUIStyle button_style; text_style = new GUIStyle() { fontSize = 20 }; button_style = new GUIStyle("button") { fontSize = 15 }; if (gameState == 0) { //初始界面 if (GUI.Button(new Rect(Screen.width / 2 - 50, 80, 100, 60), "Start Game", button_style)) { action.StartGame(); } } else if (gameState == 1) { //游戏进行中 //用户射击 if (Input.GetButtonDown("Fire1")) { Vector3 mousePos = Input.mousePosition; action.Hit(mousePos); } score = "Score: " + action.GetScore().ToString(); GUI.Label(new Rect(200, 5, 100, 100), score, text_style); round = "Round: " + action.GetCurrentRound().ToString(); GUI.Label(new Rect(400, 5, 100, 100), round, text_style); blood = action.GetBlood(); string bloodStr = "Blood: " + blood.ToString(); GUI.Label(new Rect(600, 5, 50, 50), bloodStr, text_style); } else { //游戏结束,有两种情况 if (gameState == 2) { if (action.GetScore() > HighestScore) { HighestScore = action.GetScore(); } GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 250, 100, 60), "Game Over", text_style); string record = "Highest Score: " + HighestScore.ToString(); GUI.Label(new Rect(Screen.width / 2 - 70, Screen.height / 2 - 150, 150, 60), record, text_style); } else { GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 150, 100, 70), "You Lost!", text_style); } if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 30, 100, 60), "Restart", button_style)) { action.Restart(); } } }