使用monodevelop的'意外符号'错误 [英] 'Unexpected symbol' error using monodevelop

查看:165
本文介绍了使用monodevelop的'意外符号'错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候!除了C#编程技巧基础之外,我正在学习一门教授Unity游戏开发的课程,而且我应该参加我自己的文本冒险,自由形式的部分。为此,我正在复制以前视频辅助的基本结构。然而,我发现了一些我无法解释的奇怪错误。



到目前为止这是剧本:



使用UnityEngine;使用UnityEngine.UI;使用System.Collections;



公共类游戏:MonoBehaviour {



 public文字文字; 

私有枚举状态{start,light,cave,path1,egg,TH,ocean,bEnd1,summer,basement,weed,upstairs,devil,awake,bEnd2,computer,bEnd3,GOLDEN}
private states myState;
//用于初始化
void Start(){
myState = states.start;
}

//每帧调用一次更新
void Update(){
print(myState);
if(myState == states.start){
start(); }
else if(myState == states.light){
light(); }
else if(myState == states.cave){
cave(); }
else if(myState == states.path1){
path1(); }
else if(myState == states.egg){
egg(); }
else if(myState == states.TH){
TH(); }
else if(myState == states.ocean){
ocean(); }
else if(myState == states.bEnd1){
bEnd1(); }
else if(myState == states.summer){
summer(); }
else if(myState == states.basement){
basement(); }
else if(myState == states.weed){
weed(); }
else if(myState == states.upstairs){
upstairs(); }
else if(myState == states.devil){
devil(); }
else if(myState == states.awake){
awake(); }
else if(myState == states.bEnd2){
bEnd2(); }
else if(myState == states.computer){
computer(); }
else if(myState == states.bEnd3){
bEnd3(); }
else if(myState == states.GOLDEN){
GOLDEN(); }
}
}

void start(){
text.text =这就像一个糟糕的梦想。你不知道你是怎么来到这里的,这个地方在哪里,或者你为什么来到这里,但是你知道你感到不安。+
所有这一切都是非常错误的。你应该试着找出一条出路...无论在哪里是!\ n \ n+
你可以去看远处的那个[L],调查来自附近[C]大道的声音,或者向下看[P]在......;
if(Input.GetKeyDown(KeyCode.L)){myState = states.light;}
else if(Input.GetKeyDown(KeyCode.C)){myState = states.cave;}
else if(Input.GetKeyDown((KeyCode.P)){myState = states.path1;}
}





我的问题:Unity似乎不喜欢最终可能的{字符(前置行)并说它是一个意想不到的符号。同样,该位代码中的空白也是意外的。但是,如果我删除了;在文本部分之后对于同一个块,它会对同一个块的if语句产生问题。据我所知,我正在复制必要的条目和代码,所以这很令人费解。



我想知道是不是因为我的游戏初始状态被称为以非资本S开始,而有资本S的函数存在,但可能不存在?它似乎从不介意开始,本身。



其他信息:Unity V 4.6.9.f1(根据我的课程指示简单,小专业jects)



谢谢。



编辑:您好,感谢您的快速和有用的答案,

 Kornfeld Eliyahu Peter! 

我不确定我理解你应该做什么,但添加另一个(对它和前一行只是将意外符号问题转移到{结尾处的字符}相同的声明。

道歉

我尝试过:

咨询之前,工作脚本,在官方Unity上发布论坛(此时甚至没有在Moderation中度过近3天),分析代码。

解决方案

你的第二个 void start()函数位于任何类之外。这就是为什么你会出现意外的'void'错误。



我会期望该函数应属于 MonoBehaviour 类(在 update()函数后移动最后一个结束'}'到源文件的末尾。)但是你将有两个 start()函数(移动 myState = states.start 第二个函数的代码行并删除第一个)。


  else   if (Input.GetKeyDown((KeyCode.P)){myState = states.path1;} 
- ((())

这里没有配对 - 太多或太多少...


Greetings! I'm taking a course that teaches Unity game development in addition to C# programming skill basics and I'm up to the part where I'm supposed to make my own text adventure, free-form. To do so, I'm copying the basic structure from the previous, video-assisted one. And yet, I'm finding some odd errors that I can not explain.

Here is the script so far :

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class Game : MonoBehaviour {

 public Text text;
 
 private enum states {start, light, cave, path1, egg, TH, ocean, bEnd1, summer, basement, weed, upstairs, devil, awake, bEnd2, computer, bEnd3, GOLDEN}
 private states myState;
 // Use this for initialization
 void Start () {
     myState = states.start;
 }
 
 // Update is called once per frame
 void Update () {
     print (myState);
     if (myState == states.start) {
         start(); }
     else if (myState == states.light) {
         light(); }
     else if (myState == states.cave) {
         cave(); }
     else if (myState == states.path1) {
         path1(); }
     else if (myState == states.egg) {
         egg(); }
     else if (myState == states.TH) {
         TH(); }
     else if (myState == states.ocean) {
         ocean(); }
     else if (myState == states.bEnd1) {
         bEnd1(); }
     else if (myState == states.summer) {
         summer(); }
     else if (myState == states.basement) {
         basement(); }
     else if (myState == states.weed) {
         weed(); }
     else if (myState == states.upstairs) {
         upstairs(); }
     else if (myState == states.devil) {
         devil(); }
     else if (myState == states.awake) {
         awake(); }
     else if (myState == states.bEnd2) {
         bEnd2(); }
     else if (myState == states.computer) { 
         computer(); }
     else if (myState == states.bEnd3) {
         bEnd3(); }
     else if (myState == states.GOLDEN) {
         GOLDEN(); }
 }
}

 void start () {
 text.text = "This is like a bad dream. You don't know how you got here, where this place is, or why you got here, but you know that you feel uneasy. " +
             "Something is very wrong with all of this. You should try and look for a way out of...wherever this is! \n \n  " +
             "You could go and see about that [L]ight in the distance, investigate the sound coming from a nearby [C]ave, or head down the nearby [P]ath..." ;
 if (Input.GetKeyDown(KeyCode.L)) {myState = states.light;}
 else if (Input.GetKeyDown(KeyCode.C))    {myState = states.cave;}
 else if (Input.GetKeyDown((KeyCode.P))    {myState = states.path1;}
 }



My problem : Unity seems to not like the final possible { character (pre-final line) and says it's an unexpected symbol. Similarly, the void in that bit of code is also unexpected. However, if I remove the ; after the text portion of that same block, it will instead have a problem with the "if" statement of that same block. As far as I can see, I'm copying the necessary entries and code perfectly, so this is quite puzzling.

I was wondering if it was because my game initial state is called start with a non-capital S whereas a function with a capital S exists, but possibly not? It never seemed to mind start, itself.

Other info : Unity V 4.6.9.f1 (As instructed by my course for simple, small projects)

Thank you.

Edit : Hello and thank you for your quick and helpful answer,

Kornfeld Eliyahu Peter !

I'm not sure I understand your response in terms of what I should do, but adding another ( to it and the preceding line just shifts the Unexpected Symbol problem to the { character at the end of the same statement.

Apologies

What I have tried:

Consulting prior, working script, posting on official Unity forums (Did not even come off Moderation for nearly 3 days at this point), analyzing code.

解决方案

Your second void start() function is located outside any class. That is why you get an unexpected 'void' error.

I would expect that the function should belong to the MonoBehaviour class (move the last closing '}' after the update() function to the end of the source file). But then you will have two start() functions (move the myState = states.start code line to the second function and remove the first one).


else if (Input.GetKeyDown((KeyCode.P))    {myState = states.path1;}
--      (                ((         ))

There are no pairs here - too much or too less...


这篇关于使用monodevelop的'意外符号'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆