[英]Error CS1513: } expected & CS1022: End-of-file expected - But file looks fine to me
所以基本上 Unity 控制台向我抛出以下错误,但是我现在已经查看了十几次文件,无法理解为什么我会被抛出这些错误:
CS1513:} 预期(第 52 行)
CS1022:类型或命名空间定义,或预期的文件结尾(第 87 行)
这是我的文件的代码:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System;
using System.Collections.Generic;
public class GameControl : MonoBehaviour
{
public static GameControl instance; //A reference to our game control script so we can access it statically.
public Text scoreText;
public Text wordText; //A reference to the UI text component that displays the player's score.
public GameObject gameOvertext; //A reference to the object that displays the text which appears when the player dies.
private int score = 0; //The player's score.
public bool gameOver = false; //Is the game over?
public float scrollSpeed = -1.5f;
void Awake()
{
//If we don't currently have a game control...
if (instance == null){
//...set this one to be it...
instance = this;
generateWord();
}
//...otherwise...
else if(instance != this){
//...destroy this one because it is a duplicate.
Destroy (gameObject);
}
}
public void generateWord()
{
var random = new System.Random();
var wordList = new List<string>{ "sisters","recess","creepy","false", "admit", "apparel", "top", "cattle", "precious", "sugar", "credit", "finger", "watch", "claim", "smash", "bleach", "wrist", "dad", "push", "curve"};
int index = random.Next(wordList.Count);
string word = (wordList[index]);
wordText.text = "WORD: " + word;
generateLetters(word);
}
public void generateLetters(string word)
{
public char[] charArr = word.ToCharArray();
public int wordLength = charArr.Length;
}
void Update()
{
//If the game is over and the player has pressed some input...
if (gameOver && Input.GetMouseButtonDown(0))
{
//...reload the current scene.
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
public void BirdScored()
{
//The bird can't score if the game is over.
if (gameOver)
return;
//If the game is not over, increase the score...
score++;
//...and adjust the score text.
scoreText.text = "SCORE: " + score.ToString();
}
public void BirdDied()
{
//Activate the game over text.
gameOvertext.SetActive (true);
//Set the game to be over.
gameOver = true;
}
}
任何帮助表示赞赏:)
public void generateLetters(string word) {
public char[] charArr = word.ToCharArray();
public int wordLength = charArr.Length;
}
方法不能包含公共变量,但您可以更改类中的公共变量。 像这样:
public char[] charArr; // Or private.
public int wordLength; // Just make sure it is inside the class.
// ...
public void generateLetters(string word) {
charArr = word.ToCharArray();
wordLength = charArr.Length;
}
此外,尽量使您的命名约定保持一致,您的某些函数以大写字母开头,例如BirdScored
或BirdDied
,而其他BirdDied
如generateLetters
或generateWord
以小写字母开头。
尝试在函数/变量的命名中保持一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.