我在Private Void Awake()&私人空缺开始() 脚本部分。如果有人能提供帮助,我将非常感激。
错误读取:
预期的类,委托,枚举,接口或结构。类型 命名空间定义或检测到的文件结尾。
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;
}
答案 0 :(得分:0)
您未正确关闭文件中的花括号({})。
您的班级GameManager
在第18行结束,您的方法Awake
无处开始,这是不正确的。
方法需要放在类中。这是你的问题。