FlappyBird后期完善
来源:互联网 发布:studio美图软件 编辑:程序博客网 时间:2024/05/01 02:09
一、新增一个MainMenuController.cs,管理MainMenu场景的NGUI交互
using UnityEngine;using System.Collections;public class MainMenuController : MonoBehaviour { //Tween public TweenPosition welcomeWidget; public TweenPosition settingsWidget; public TweenPosition resetScoresWidget; //Save the value of level private int curentGameLevle; //Judged the toggle private bool toggleValue; //save the time of game when is starting private float timeCount; void Awake() { MainSeceneManager.gameLevel = 5; MainSeceneManager.openSound = true; } ///************************************* ///click the button of resetScores ///************************************* //ensure whether reset game scores public void ClickYes() { resetScoresWidget.PlayReverse(); settingsWidget.PlayForward(); PlayerPrefs.SetFloat("score",0); } public void ClickNo() { resetScoresWidget.PlayReverse(); settingsWidget.PlayForward(); } //**************************************** //Click the button of WelcomeWidget //**************************************** public void ClickPlayButton() { Application.LoadLevel("StartGame"); } public void ClickOptionsButton() { welcomeWidget.PlayForward(); settingsWidget.PlayForward(); } public void ClickExitButton() { Application.Quit(); } ///************************************** /// click the button of optionWeidget /// ************************************* //Click the resetScoresButton public void ChangeGameLevel() { switch (UIPopupList.current.value.Trim()) { case "Easy": curentGameLevle = 5; break; case "Simple": curentGameLevle =7; break; case "Hard": curentGameLevle=9; break; } } public void ClickResetScoresButton() { resetScoresWidget.PlayForward(); settingsWidget.PlayReverse(); } public void ClickBackButton() { welcomeWidget.PlayReverse(); settingsWidget.PlayReverse(); } public void ClickSaveAndBackButton() { MainSeceneManager.gameLevel = curentGameLevle; MainSeceneManager.openSound = toggleValue; welcomeWidget.PlayReverse(); settingsWidget.PlayReverse(); } public void ClickEasyButton() //GameLevel Button and Save the value of level { curentGameLevle = 5; } public void ClickSimpleButton() { curentGameLevle = 7; } public void ClickHardButton() { curentGameLevle = 9; } public void ClickSoundButton() //Control sound whether closed { toggleValue = UIToggle.current.value; }}
二、删除结束场景,将ui放在StartScene场景中,优化脚本
新增GameOverMenu.cs
using UnityEngine;using System.Collections;public class GameOverMenu : MonoBehaviour { //get the object 's UILabel of component public UILabel currentScores; public UILabel bestScores; //get the game over menu public Object gameOverMenu; private float currentScore; //void Awake(){ // JudgeTheGameOverMenu(); // //display the current score and best score by Label // UpdateTheScores(currentScore); // //print("GameOverMenu_currentScore:"+currentScore); //} //private void JudgeTheGameOverMenu() //{ // if (gameOverMenu) // { // //save current scores // currentScore = RemenberScores.currentScore; // } //} public void StartGame() { Application.LoadLevel("StartGame"); } public void LoadMainMenu() { Application.LoadLevel("MainScene"); } public void Exit() { Application.Quit(); } public void UpdateTheScores(float currentScore) { float bestScore = PlayerPrefs.GetFloat("score", 0); if (currentScore > bestScore) { bestScore = currentScore; GameObject.Find("Title").GetComponent<UILabel>().text = "Good Score!"; } else if(currentScore<bestScore) { GameObject.Find("Title").GetComponent<UILabel>().text = "No Good!"; } else { GameObject.Find("Title").GetComponent<UILabel>().text = "Just so so!"; } PlayerPrefs.SetFloat("score",bestScore); currentScores.text = currentScore + ""; bestScores.text = bestScore + ""; }}
修改GameManager.cs
using UnityEngine;using System.Collections;public class GameManager : MonoBehaviour { /// <summary> /// the class used to control the Game /// </summary> public static GameManager gameInstance; //the Game State public enum GameState { GAMESTART = 0, GAMEISPLAYING = 1, GAMEOVER = 2 }; public int currentGameState; //save the collide count public int collideCount=0; //choose a background to transform position public Transform firstBackGround; //Save the current scores public int currentScores=0; //achieve the game object public GameObject scoreTitle; private int delayTime = 2; //receive bird and GameOverMenu private GameObject bird; private GameObject gameOverMenu; //private AudioSource startSound; void Awake() { gameInstance = this; scoreTitle.SetActive(false); currentGameState = (int)GameState.GAMESTART; bird = GameObject.FindGameObjectWithTag("Player"); gameOverMenu = GameObject.Find("GameOverMenu"); PlayTheStartSound(); } void Update() { if(currentGameState ==(int)GameState.GAMESTART) { gameOverMenu.SetActive(false); if(Input.GetMouseButtonDown(0)) { scoreTitle.SetActive(true); GameObject.Find("FlappyBird").SetActive(false); currentGameState = (int)GameState.GAMEISPLAYING; bird.SendMessage("GetTheGameBegin"); } } if(currentGameState==(int)GameState.GAMEOVER) { RemenberScores.currentScore = currentScores; StartCoroutine("DisplayScores"); } } IEnumerator DisplayScores() { yield return new WaitForSeconds(delayTime); gameOverMenu.SetActive(true); gameOverMenu.SendMessage("UpdateTheScores", currentScores); } private void PlayTheStartSound() { if (currentGameState == (int)GameState.GAMESTART) { if (MainSeceneManager.openSound) { audio.Play(); } } }}
新增MainSceneManager.cs脚本
using UnityEngine;using System.Collections;public class MainSeceneManager { //Save the game level public static int gameLevel; //Judged whether open the sound public static bool openSound;}
修改ColliderFloor.cs脚本,其他脚本作类似修改
using UnityEngine;using System.Collections;public class ColliderFloor : MonoBehaviour { void OnCollisionEnter(Collision gameObject) { if (gameObject.gameObject.tag == "Player") { GameManager.gameInstance.collideCount++; if (MainSeceneManager.openSound && GameManager.gameInstance.collideCount<=1) { audio.Play(); } GameManager.gameInstance.currentGameState = (int)GameManager.GameState.GAMEOVER; } }}
0 0
- FlappyBird后期完善
- FlappyBird开发——后期完善
- SQL行转列(暂时记录,后期完善改文章)
- 初步学习java---简单画图板(注:画板还没完善,后期逐步完善)
- 怎样学习java——关于我的建议(后期完善)
- 接口 怎么 部署到 阿里服务器的 初步学习知识后期还要完善
- C#FlappyBird
- Unity3D FlappyBird
- 完善
- 完善
- 后期修行
- 后期学习
- 后期绑定
- 后期绑定
- cocos2dx 3.0 flappybird -----001
- cocos2dx 3.0 flappybird -----002
- cocos2dx 3.0 flappybird -----003
- cocos2dx 3.0 flappybird -----004
- 日拱一卒(十四)
- 飞机大战-5
- Swift基础语法: 27 - Swift的全局变量和局部变量, 类型属性, 获取和设置类型属性的值
- 整理有用的Android开发资源
- Uinity学习的一些知识点
- FlappyBird后期完善
- 2013-03-17---二叉树递归,非递归实现(附代码)深度,叶子节点数量,逐行打印二叉树
- 打印fibonacci数列
- 分享几个AndroidSDK镜像源
- start_kernel分析
- 推荐算法
- 通过socket发送结构体
- 黑马程序员——堆和栈的区别(转载)
- 如何学习Java_不走弯路,就是捷径