unity3d学习——问题遗留(未解决)
来源:互联网 发布:python re.match 编辑:程序博客网 时间:2024/05/20 11:53
游戏本体并没有完成,所以这篇博客仅供日后个人参考
没有完成的主要原因是教程代码与现用代码出现不符,当然这其实没什么影响,因为已经找到了可以使用的方法
找到了是找到了,那么问题还是出现报错,应该是出在两部分代码的链接上
下面是两个部分的代码:
第一部分——消灭模块
using System.Collections;using System.Collections.Generic;using UnityEngine;public class Destory : MonoBehaviour { public GameObject explosion; public GameObject playerExplosion; public Done_GameController gameController; public int scoreValue; void start() { GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent<Done_GameController>(); } if (gameControllerObject == null) { Debug.Log("Can not find GameContraller Scripts"); } } void OnTriggerEnter(Collider other) { if (other.tag == "Wall"||other.tag == "Enemy")//使物体不会因碰撞被消除 { return; } if (other.tag == "Player")//玩家爆炸效果 { Instantiate(playerExplosion, other.transform.position, other.transform.rotation); gameController.GameOver(); } if (explosion != null)//行星爆炸效果 { Instantiate(explosion, other.transform.position, other.transform.rotation); } //玩家以及行星因碰撞消失 //gameController.AddScore(scoreValue); Destroy(other.gameObject); Destroy(this.gameObject); }}然后是gameController
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class GameContraller : MonoBehaviour { public GameObject[] hazards;//这里存放之前预设好的游戏物体小行星 public Vector3 spawnValues;//随即生成小行星的未知 public int hazardCount;//每一波生成的数量 public float spawnWait;//每一个生成的时间 public float startWait;//第一波等待的时间 public float waveWait;//每一波等待的时间 public Text scoreText;//得分 public Text gameOverText;//游戏结束 public Text restartText;//重新开始 private int score; private bool gameOver; private bool restart; // Use this for initialization void Start () { gameOverText.text = ""; restartText.text = ""; gameOver = false; restart = false; score = 0; UpdateScore(); StartCoroutine(SpawnWave());} void Update() { if (restart) { if (Input.GetKeyDown(KeyCode.R)) { Application.LoadLevel(Application.loadedLevel); } } } IEnumerator SpawnWave() { yield return new WaitForSeconds(startWait); while (true) { for (int i = 0; i < hazardCount; i++) { //这一波代码很难理解。。。。 GameObject hazard = hazards[Random.Range(0, hazards.Length)];//从数组中选择一个物体 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);//物体出现的位置 Instantiate(hazard, spawnPosition, Quaternion.identity); yield return new WaitForSeconds(spawnWait); } yield return new WaitForSeconds(waveWait); if (gameOver) { restartText.text = "Press 'R' for Restart"; restart = true; break; } } } //积分增加 public void AddScore(int newScoreValue) { score += newScoreValue; UpdateScore(); } //更新积分显示 void UpdateScore() { scoreText.text = "Score:" + score; } public void GameOver() { gameOverText.text = "Game Over!!!"; gameOver = true; }}
Destory.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Sprites/Destory.cs:37)
这段代码使用后没有计分(当然是因为我把计分功能注释掉了)没有重新开始,没有死亡,即玩家不会被消灭
以上问题预后解决,完成后发文
阅读全文
0 0
- unity3d学习——问题遗留(未解决)
- 解决遗留的问题
- movingSquare——之前遗留的问题
- 数组替换——(问题还未解决)
- 使用soap组件发送webs遗留未结问题
- iframe问题(未解决)
- win10删除vmware12后,重新安装失败(遗留注册表问题)解决总结
- 使用SQL2005强制计划解决遗留系统性能问题
- angularjs 解决之前的遗留的一个问题
- 未解决的问题(vector)
- 未解决的问题
- 未解决的问题。
- 未解决的问题
- 未解决的问题
- 未解决之问题
- 未解决的问题
- JavaMail 问题--未解决
- 未解决的问题
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time(模拟)
- 实验二 线性表综合实验(循环链表)
- JavaScript高级程序设计——知识点整理(Part 2)
- Milking Grid POJ
- Python列表推导式求素数
- unity3d学习——问题遗留(未解决)
- [Tyvj P4876]近似排列计数[50]
- 相邻两数最大差值 -- 算法小结
- 智能家居成功接入互联网,实现远程访问
- 数据挖掘概念与技术第三版 范明 孟晓峰译 第四章习题答案
- Mac环境下编译Android平台的ffmpeg
- 【九】Java IO流(上)
- mac通过vnc远程桌面raspberry pi
- 二. Urllib库详解