My last post was rejected and i did not get an answer on why so i test again.
Hi i’m learning c# and do so by making an old school text adventure. my problem is i cant figure out one simple thing: i got one c# file that starts the game and make you make some questions up till one point where you make a big decision and change the story forever! it’s like one answer you go do that an then all this happens and the other answer this stuff happens and because the story is splitting in two ways here i want two separate files whit the with the continuation of the story. here is the last part of my “first” part of the story and game:
void out_1()
{
text.text = "You're out of your house, and you must decide.
" +
“Take the Car or the Dirt bike?” +
"
" +
“C to take the Car, D to take the Dirt bike”;
if (Input.GetKeyDown(KeyCode.C)) { myState = States.car; }
else if (Input.GetKeyDown(KeyCode.D)) { myState = States.dirtBike; }
}
so basically i want:
myState = States.car; } go to one c# file
and
myState = States.dirtBike; } to an other c# file
how can i make this happen?
Main class:
using UnityEngine;
using UnityEngine.UI;
public class test : MonoBehaviour {
public enum States
{
car,
dirtBike,
None
}
public test.States myState;
Text text;
bool _choice = true;
void Awake(){
myState = test.States.None;
}
void Start()
{
text = GetComponent<Text>();
text.text = "You're out of your house, and you must decide.
" +
“Take the Car or the Dirt bike?” +
"
" +
“C to take the Car, D to take the Dirt bike”;
}
void Update(){
if (Input.GetKeyDown(KeyCode.C) && _choice){
myState = test.States.car;
_choice = false;
}
else if (Input.GetKeyDown(KeyCode.D) && _choice){
myState = test.States.dirtBike;
_choice = false;
}
}
}
Car Class:
using UnityEngine;
public class Car : MonoBehaviour {
public test _test; //assign it in Inspector or Initialize it in Awake() / Start()
bool _active = true; //so it won't get called every frame after it's false
void Update () {
if(_test.myState == test.States.car && _active){
Debug.Log("Go with Car");
_active = false;
}
}
}
DirtBike class :
using UnityEngine;
public class DirtBike : MonoBehaviour {
public test _test; //assign it in Inspector or Initialize it in Awake() / Start()
bool _active = true;
void Update () {
if(_test.myState == test.States.dirtBike && _active){
Debug.Log("Go with DirtBike");
_active = false;
}
}
}