【发布时间】:2017-02-25 03:31:15
【问题描述】:
我在 Private Void Awake() 和 Private Void Start() 中出现错误 脚本上的部分。如果有人可以提供帮助,我将不胜感激。
读取的错误:
预期的类、委托、枚举、接口或结构。类型 命名空间定义,或检测到文件结尾。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject[] m_Tanks;
private float m_gameTime = 0;
public float GameTime { get { return m_gameTime; } }
public enum GameState
{
Start,
Playing,
GameOver
};
private GameState m_GameState;
public GameState State { get { return m_GameState; } }
}
private void Awake()
{
m_GameState = GameState.Start;
}
private void Start()
{
for (int i = 0; i < m_Tanks.Length; i++)
{
m_Tanks[i].SetActive(false);
}
m_TimerText.gameObject.SetActive(false);
m_Exit.gameObject.SetActive(false);
m_HighScores.LoadScoresFromFile();
}
void Update()
{
switch (m_GameState)
{
case GameState.Start:
if (Input.GetKeyUp(KeyCode.Return) == true)
{
m_GameState = GameState.Playing;
for (int i = 0; i < m_Tanks.Length; i++)
{
m_Tanks[i].SetActive(true);
}
}
break;
case GameState.Playing:
bool isGameOver = false;
m_gameTime += Time.deltaTime;
int seconds = Mathf.RoundToInt(m_gameTime);
if (OneTankLeft() == true)
{
isGameOver = true;
}
else if (IsPlayerDead() == true)
{
isGameOver = true;
}
if (isGameOver == true)
{
m_GameState = GameState.GameOver;
}
break;
case GameState.GameOver:
if (Input.GetKeyUp(KeyCode.Return) == true)
{
m_gameTime = 0;
m_GameState = GameState.Playing;
for (int i = 0; i < m_Tanks.Length; i++)
{
m_Tanks[i].SetActive(true);
}
}
break;
}
if (Input.GetKeyUp(KeyCode.Escape))
{
Application.Quit();
}
}
private bool OneTankLeft()
{
int numTanksLeft = 0;
for (int i = 0; i < m_Tanks.Length; i++)
{
if (m_Tanks[i].activeSelf == true)
{
numTanksLeft++;
}
}
return numTanksLeft <= 1;
}
private bool IsPlayerDead()
{
for (int i = 0; i < m_Tanks.Length; i++)
{
if (m_Tanks[i].activeSelf == false)
{
if (m_Tanks[i].tag == "Player")
return true;
}
}
return false;
}
【问题讨论】:
-
如果缩进得当,更容易识别大括号不平衡的位置。