Hello I am making a simple text adventure game to get into C# coding and unity. But I want to tweak my code a little bit from the tutorial and I have been experimenting with no luck…
Basically I want it to display Text Display #1 If it is true, and Text Display #2 if it is false.
I am using GotSword just as an experiment because it is in the first scene. but the if statement using it is towards the bottom of my code.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextController : MonoBehaviour {
public Text text;
private enum States {tent, SearchTent, SearchYourself, LeaveTent, SearchCampSite, InspectCar};
private States myState;
public bool GotSword;
public bool GotTrinket;
public bool GotKeys;
// Use this for initialization
void Start () {
myState = States.tent;
}
// Update is called once per frame
void Update () {
print (myState);
if (myState == States.tent) {state_tent();}
else if (myState == States.SearchTent) {state_SearchTent();}
else if (myState == States.SearchYourself) {state_SearchYourself();}
else if (myState == States.LeaveTent) {state_LeaveTent();}
else if (myState == States.InspectCar) {state_InspectCar();}
}
void state_tent(){
text.text = "You wake up in what seems to be a tent, you have no recollection of where you are or " +
"how in the hell you got here. You look around the tent in a daze and notice there could " +
"be some things of use in here.
" +
“Press -T- to search the Tent, Press -Y- to search Yourself, and press -L- to Leave the tent.”;
if (Input.GetKeyDown(KeyCode.T))
{myState = States.SearchTent;
}else if (Input.GetKeyDown(KeyCode.Y))
{myState = States.SearchYourself;}
else if (Input.GetKeyDown(KeyCode.L))
{myState = States.LeaveTent;}
}
void state_SearchTent(){
text.text = "You search through all the stuff in the tent, dumping out a backpack full of clothes, " +
"and anything else around you to find something that could help you. " +
"You find what looks to be a sword in your sleeping bag, it looks studry..... " +
"Kind of, So you decide to take it with you....
" +
“Press -B- to go Back to previous screen.”;
GotSword = true;
if (Input.GetKeyDown (KeyCode.B))
{myState = States.tent;}
}
void state_SearchYourself(){
text.text = "You search your pockets, turninging them inside out but find nothing other than a shiney trinket " +
"of no real value, but you put it back in your pocket anyway.
" +
“Press -B- to go Back to the inside of the tent.”;
GotTrinket = true;
if (Input.GetKeyDown (KeyCode.B))
{myState = States.tent;}
}
void state_LeaveTent(){
text.text = "You step outside of the tent, looks like you are at a campsite in the middle of no where..... " +
"I wonder how you got here? Who cares! Right now lets find a way out of here!!!
" +
“Press -B- to go Back into the tent, Press -S- to Search the campsite for clues.”;
if (Input.GetKeyDown (KeyCode.B))
{myState = States.tent;}
else if (Input.GetKeyDown(KeyCode.S))
{myState = States.SearchCampSite;}
}
void state_InspectCar(){
if (GotSword = true()){
text.text = “You walk over to the car, try to use the keys on the door and BAM! The door opens, so you get in and drive away. CONGRADULATIONS YOU MADE IT!”;
} else if(GotSword = false){
text.text = "You walk over to the car cautiously keeping an eye out for anyone and then suddenly trip over a stick… " +
"Smooth move budyy… You get back yp and brush yourself off and continue over to the car " +
"You look around but there is no one inside or around the car and it is locked up tight.
" +
“Press -B- to go Back to the Campsite”;
if (Input.GetKeyDown (KeyCode.B))
{myState = States.SearchCampSite;}
}
}
}
EDIT: By the way this is what i get in the unity console if it helps.
Assets/TextController.cs(70,35): error CS0119: Expression denotes a value', where a
method group’ was expected
Idk if I am trying to do it wrong or what