Я новичок в Unity от 2018.2.7f1 (64-битная версия).
В Space Shooter, официальных руководствах по Unity, устранены проблемы.
● GUIText устарел.Теперь нужно использовать Text.
● Application.LoadLevel и LoadedLevel устарели.Теперь нужно использовать SceneManager.
Я застреваю здесь.
ScoreText работает.Работало в режиме Game Play.Но RestartText и GameOverText не работают.Когда персонаж игрока погибает, волны Вражеского риска просто продолжают идти, а тексты не отображаются.
Как я могу решить эти проблемы?Ребята, дайте мне знать, где мне починить? Я прочитал документальный фильм о Text и SceneManager и все еще не получил его.В консоли не отображаются ошибки.
и т. Д.Я делаю похожую игру-стрелялку, но база такая же, как у Space Shooter.Это не страшно, просто я заметил.
● Код GameController
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;
}
}
● DestroyByContact Code
</p>
<code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyByContatct_Summon : MonoBehaviour
{
public int scoreValue;
private GameController gameController;
void Start()
{
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent<GameController>();
}
if (gameController == null)
{
Debug.Log("Cannot find 'GameController' script");
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Enemy")
{
return;
}
if (other.tag == "EnemySummon")
{
return;
}
if (other.tag == "BackGround")
{
return;
}
if (other.tag == "Player")
{
gameController.GameOver ();
}
gameController.AddScore(scoreValue);
Destroy(other.gameObject);
Destroy(gameObject);
}
}
</code>