我是2018.2.7f1(64bit)Unity的新手。
Space Shooter的官方Unity教程已过时。
●GUIText已过时。现在必须使用文本。
●Application.LoadLevel和LoadedLevel已过时。现在必须使用SceneManager。
我被困在这里。
ScoreText正在运行。它在游戏模式下工作。但是RestartText和GameOverText不起作用。当玩家角色死亡时,危险敌人会继续前进,并且文本不会显示。
我该如何解决这些问题?你们会让我知道应该在哪里解决吗?我读过纪录片和SceneManager的纪录片,但仍然听不懂。控制台中未显示任何错误。
等我正在制作类似的射击游戏,但与Space Shooter的基础相同。我注意到这没什么大不了的。
●GameController代码
findCookies("search").slice(-5).forEach(function(fullName){deleteCookie(fullName);});
●按联系方式销毁
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
public GameObject EnemySummon;
public Vector2 spawnValues;
public int EnemySummonCount;
public float SpawnWait;
public float startWait;
public float waveWait;
public Text scoreText;
public Text restartText;
public Text gameOverText;
private bool gameOver;
private bool restart;
private int score;
void Start()
{
gameOver = false;
restart = false;
restartText.text = null;
gameOverText.text = null;
score = 0;
UpdateScore();
StartCoroutine (SpawnWaves());
}
void Update()
{
if (restart)
{
if (Input.GetKeyDown (KeyCode.R))
{
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
}
}
}
IEnumerator SpawnWaves ()
{
while (true)
{
yield return new WaitForSeconds(startWait);
for (int i = 0; i < EnemySummonCount; i++)
{
Vector2 spawnPosition = new Vector2(spawnValues.x, UnityEngine.Random.Range(-spawnValues.y, spawnValues.y));
Quaternion spawnRotation = Quaternion.identity;
Instantiate(EnemySummon, spawnPosition, spawnRotation);
yield return new WaitForSeconds(SpawnWait);
if (gameOver)
{
restartText.text = "Press 'R' for Restart";
restart = true;
break;
}
}
yield return new WaitForSeconds(waveWait);
}
}
public void AddScore (int newScoreValue)
{
score += newScoreValue;
UpdateScore();
}
void UpdateScore ()
{
scoreText.text = "Score: " + score;
}
public void GameOver ()
{
gameOverText.text = "Game Over!";
gameOver = true;
}
}
答案 0 :(得分:0)
将gameOver条件放入wave循环很奇怪。而且startWait只需要执行一次。
IEnumerator SpawnWaves ()
{
yield return new WaitForSeconds(startWait);
while (true)
{
for (int i = 0; i < EnemySummonCount; i++)
{
Vector2 spawnPosition = new Vector2(spawnValues.x, UnityEngine.Random.Range(-spawnValues.y, spawnValues.y));
Quaternion spawnRotation = Quaternion.identity;
Instantiate(EnemySummon, spawnPosition, spawnRotation);
yield return new WaitForSeconds(SpawnWait);
}
if (gameOver)
{
restartText.text = "Press 'R' for Restart";
restart = true;
break;
}
yield return new WaitForSeconds(waveWait);
}
}