/// <summary> /// 改变游戏状态 /// </summary> /// <param name="state"></param> public void ChangeGameState(GAME_STATE state) { if (state == GAME_STATE.START) { // UI界面状态切换 m_UiStart.SetActive(true); m_UiGame.SetActive(false); m_UiEnd.SetActive(false); // 背景音乐状态切换 m_AudioSourceStart.Stop(); // 武器状态切换 m_Weapon.ChangeMoveState(false); // 飞盘定时器状态切换 m_FeiPanManager.StopCreateFeiPan(); // 游戏状态切换 m_GameState = GAME_STATE.START; // 开始时间切换 m_StartTime = 0; // 分数值切换 SetScore(0); } else if (state == GAME_STATE.PLAYING) { // UI界面状态切换 m_UiStart.SetActive(false); m_UiGame.SetActive(true); m_UiEnd.SetActive(false); // 背景音乐状态切换 m_AudioSourceStart.Play(); // 武器状态切换 m_Weapon.ChangeMoveState(true); // 飞盘定时器状态切换 m_FeiPanManager.StartCreateFeiPan(); // 游戏状态切换 m_GameState = GAME_STATE.PLAYING; // 开始时间切换 m_StartTime = Time.time; // 启动游戏状态切换 Invoke("GameEnd", TOTAL_TIME); // 分数值切换 SetScore(0); } else if (state == GAME_STATE.END) { // UI界面状态切换 m_UiStart.SetActive(false); m_UiGame.SetActive(false); m_UiEnd.SetActive(true); // 背景音乐状态切换 m_AudioSourceStart.Stop(); // 武器状态切换 m_Weapon.ChangeMoveState(false); // 飞盘定时器状态切换 m_FeiPanManager.StopCreateFeiPan(); // 游戏状态切换 m_GameState = GAME_STATE.END; // 开始时间切换 m_StartTime = 0; } }
// 切换游戏状态 public void ChangeGameState(GameState state) { mGameState = state; if (mGameState == GameState.START) { // UI切换 mStartUI.SetActive(true); mGameUI.SetActive(false); mEndUI.SetActive(false); // 背景音乐切换 mBgAudioScoure.Stop(); // 武器控制切换 mWeapon.ChangeCanMove(false); } else if (mGameState == GameState.GAME) { // UI切换 mStartUI.SetActive(false); mGameUI.SetActive(true); mEndUI.SetActive(false); // 背景音乐切换 mBgAudioScoure.Play(); // 武器控制切换 mWeapon.ChangeCanMove(true); // 开始生成飞盘 mFeiPanManager.StartCreateFeiPan(); // 开始倒计时 StartTime(); } else if (mGameState == GameState.END) { // UI切换 mStartUI.SetActive(false); mGameUI.SetActive(false); mEndUI.SetActive(true); // 背景音乐切换 mBgAudioScoure.Stop(); // 武器控制切换 mWeapon.ChangeCanMove(false); // 停止生成飞盘 mFeiPanManager.StopCreateFeiPan(); // 移除所有已经存在的飞盘 mFeiPanManager.RemoveFeiPan(); // 停止倒计时 StopTime(); } }
// Update is called once per frame public void ChangeGameStatus(GameStatus status) { GameStatus m_GameStatus = status; if (m_GameStatus == GameStatus.START) { m_StartUI.SetActive(true); m_GameUI.SetActive(false); m_EndUI.SetActive(false); m_AudioSource.Stop(); m_weapon.ChangeHandMove(false); m_FeiPanManager.StopCreateFeiPan(); GameObject[] trash = GameObject.FindGameObjectsWithTag("Trash"); for (int i = 0; i < trash.Length; i++) { GameObject.Destroy(trash[i]); } } else if (m_GameStatus == GameStatus.GAME) { Score = 0; m_GUIText.text = "分数:0"; time = 20; time_GUIText.text = "时间:20秒"; m_GameUI.SetActive(true); m_StartUI.SetActive(false); m_EndUI.SetActive(false); m_AudioSource.Play(); m_weapon.ChangeHandMove(true); m_FeiPanManager.StartCreateFeiPan(); StartTime(); } else { m_EndUI.SetActive(true); m_StartUI.SetActive(false); m_GameUI.SetActive(false); m_AudioSource.Stop(); OverScore(); m_weapon.ChangeHandMove(false); m_FeiPanManager.StopCreateFeiPan(); } }
/// <summary> /// 切换游戏状态 /// </summary> /// <param name="state">目标状态</param> public void ChangeGameState(GameState state) { //存储传递过来的状态 gameState = state; if (gameState == GameState.START) //开始游戏 { m_StartUI.SetActive(true); m_GameUI.SetActive(false); m_EndUI.SetActive(false); bgAudio.Stop(); weapon.setCanMove(false); feipanManager.StopCreateFeiPan(); } else if (gameState == GameState.GAME) //游戏中 { m_StartUI.SetActive(false); m_GameUI.SetActive(true); m_EndUI.SetActive(false); bgAudio.Play(); weapon.setCanMove(true); StartTime(); feipanManager.StartCreateFeiPan(); } else if (gameState == GameState.END) //结束游戏 { m_StartUI.SetActive(false); m_GameUI.SetActive(false); m_EndUI.SetActive(true); bgAudio.Stop(); weapon.setCanMove(false); feipanManager.StopCreateFeiPan(); feipanManager.RemoveFeiPan(); } }