FlappyBird开发——后期完善
来源:互联网 发布:宝元lnc编程 编辑:程序博客网 时间:2024/05/21 06:17
一、新增一个MainMenuController.cs,管理MainMenu场景的GNUI交互
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后期完善
- FlappyBird开发总结(二)——场景
- FlappyBird开发总结(七)—— GameOver计分板
- FlappyBird开发总结(五)——背景延伸
- FlappyBird开发总结(八)——MainScene场景
- 怎样学习java——关于我的建议(后期完善)
- FlappyBird—仅供娱乐
- FlappyBird开发总结(一)—— 开发前所必备
- FlappyBird开发总结(三)——小鸟脚本,让小鸟煽动翅膀
- FlappyBird开发总结(六)—— 计分制的实现
- FlappyBird开发总结(四)—— GameManager.cs脚本,游戏控制
- 匆匆——后期感悟
- 目录---FlappyBird游戏开发教程
- 【cocos2dx-3.0beta-制作flappybird】——背景介绍
- Unity2D 制作小游戏FlappyBird心得—Unity5学习笔记
- Openwrt开发日志——完善一个界面
- SQL行转列(暂时记录,后期完善改文章)
- C++的五种内存存储区
- reids中内部数据结构->双向链表
- HDU-2672 god is a girl 斐波那契数列
- hdu 2818 Building Block
- hdu 2063 过山车(匈牙利算法)
- FlappyBird开发——后期完善
- 关于 Ajax Post 的乱码问题处理方法
- C#中实现多继承的方法作者:张宏杰 字体:[增加 减小] 类型:转载
- P51第20题
- LeetCode_Rotate Image
- hdu 2203 亲和串
- 利用 CocoaLumberjack 搭建自己的 Log 系统
- 八皇后问题 回溯法
- 杭电 HDU ACM 1420 Prepared for New Acmer