Unity (四)
来源:互联网 发布:淘宝的海外直购在哪 编辑:程序博客网 时间:2024/06/06 05:03
声明,最近这几篇博客都是我的笔记,所以没仔细解释,请原谅~~~
今天终于把Space_Shooter搞完了。但是视频里面的GUIText在4.6版本以上不能用。老大说,这个不用在意,因为我们要用的是恩谷一。
上代码——GameController
//在游戏场景中生成障碍物;using UnityEngine;using System.Collections;public class GameController : MonoBehaviour { public GameObject hazard; public Vector3 spawnValues; public int hazardCount; //设置循环的次数; public float spawnWait; public float startWait; public float waveWait; public Canvas scoreText; private int score; public string restartText; public string gameoverText; private bool gameOver; private bool restart; //第一帧自动调用; void Start () { gameOver = false; restart = false; restartText = ""; gameoverText = ""; score = 0; UpdateScore(); StartCoroutine(SpawnWaves()); } void Update() { if (restart) { if (Input.GetKeyDown(KeyCode.R)) { Application.LoadLevel(Application.loadedLevel); } } } //hazard孵化器; IEnumerator SpawnWaves () { yield return new WaitForSeconds(startWait); while(true) { for (int i = 0; i < hazardCount; i++) { Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z); Quaternion spawnRotation = Quaternion.identity; Instantiate(hazard, spawnPosition, spawnRotation); yield return new WaitForSeconds(spawnWait); } yield return new WaitForSeconds(waveWait); if (gameOver) { restartText = "Press 'R' for Restart "; restart = true; break; } } } public void AddScore(int newScoreValue) { score += newScoreValue; UpdateScore(); } void UpdateScore() { //scoreText.guiText.text = "Score: " + score; //scoreText.guiText.text = "Score:"; } public void GameOver() { gameoverText = "Game Over"; gameOver = true; }}这里面那个重新开始如下
if (Input.GetKeyDown(KeyCode.R))//如果按键是‘R’
{
Application.LoadLevel(Application.loadedLevel);//重新载入场景,这里重载的是本身的场景;
}
要下大雨了,先撤了~~~~~~
0 0
- Unity (四)
- unity ngui学习(四)
- Unity代码日常(四)
- Unity for Absolute Beginners(四)
- Unity 客户端框架(四):资源管理器
- Unity API(四):Transform与Time
- Unity学习笔记(四)----Survival Shooter
- Unity 客户端框架(四):资源管理器
- Unity小技巧介绍(四)
- Unity Editor 基础篇(四):Handles
- Unity常用插件Dotween(四)
- Unity之CreateGameObjectWithHideFlags-四
- Unity四种坐标系
- 【unity优化四】内存
- Unity四种坐标系
- Unity四种坐标系
- unity总结四
- Unity Shader (四)Alpha测试(alpha test)
- mac上搭建svn服务器
- 2015/8/7/C-S/通过服务器转发消息
- [C/C++标准库]_[初级]_[std::vector的多线程读写问题]
- TCP/IP协议三次握手
- 【读书笔记】iOS-本地文件和数据安全注意事项
- Unity (四)
- Contest 5 1007 MZL's simple problem
- MongoDB 索引建立机制
- hdu1394
- 解决WebService中调用dll读取不到ini文件的问题
- 如何用openpyxl操作excel文档
- OJ: Two Sum
- 解决sqoop导入关系库更新联合主键的问题
- js继承例子