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;
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 = "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.