Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 10-May-17 1:36am
v2

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).
 
Share this answer
 
Comments
Chill Naga 10-May-17 7:49am    
Thank you, the Unexpected Symbol errors are gone with what you've suggested!
All that is left is to define the other states, which should go better !

I appreciate the time taken.
C#
else if (Input.GetKeyDown((KeyCode.P))    {myState = states.path1;}
--      (                ((         ))
There are no pairs here - too much or too less...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900