Hey all.
I’ve started trying to learn basic C# and unity as of last week, I’ve been spending hours daily watching tutorials, aswell as watching a course I signed up to and just trying to figure stuff out on my own…
With all that being said, this stuff is extremely overwhelming, I don’t want to give up but the more I try to implement my ideas into code the more complicated and confusing it gets… I guess that’s how it is for everyone though.
I decided to take it down a notch and focus on getting to know C# better and to make a somewhat simple text adventure game… which turns out to be equally as hard for me.
Instead of moving through scenes to continue the story, I’m trying to just change states, where the text will change for both the story and button options. My current problem is not being able to move past state_1 and state_2 methods, like it doesn’t even register on the EventSystem… it seems to me as if I need to reset the button in order for it to choose another state or something.
Or even a better alternative would be to have some sort of a database script to hold all these states and have the buttons call different states depending on the one that is currently running… No idea where to even begin on that.
Here’s the visual:
here’s the dumb script I wrote:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine;
public class NewTextManager : MonoBehaviour
{
public Text theMainText;
public Text buttonText1;
public Text buttonText2;
public Button Button1;
public Button Button2;
public bool selection1;
public bool selection2;
public enum States { mainstate, state_1, state_2, state_3, state_4 }
private States theState;
void Start()
{
theState = States.mainstate;
}
void OnEnable()
{
Button1.onClick.AddListener(delegate { selection1 = true; });
Button2.onClick.AddListener(delegate { selection2 = true; });
}
void Update()
{
if (theState == States.mainstate)
{
mainstate();
}
if (theState == States.state_1)
{
state_1();
}
if (theState == States.state_2)
{
state_2();
}
if (theState == States.state_3)
{
state_3();
}
if (theState == States.state_4)
{
state_4();
}
}
void mainstate()
{
theMainText.text = "something happens";
buttonText1.text = "do something";
buttonText2.text = "do another thing";
if (selection1 == true)
{
theState = States.state_1;
}
else if (selection2 == true)
{
theState = States.state_2;
}
}
void state_1()
{
EventSystem.current.SetSelectedGameObject(null); //the only reason i use these is to deselect the button so it won't be highlighted anymore after being clicked
theMainText.text = "something happens again";
buttonText1.text = "option1";
buttonText2.text = "option2";
if (selection1 == true)
{
theState = States.state_3;
}
else if (selection2 == true)
{
theState = States.state_4;
}
}
void state_2()
{
EventSystem.current.SetSelectedGameObject(null);
theMainText.text = "something happens again";
buttonText1.text = "option1";
buttonText2.text = "option2";
if (selection1 == true)
{
theState = States.state_3;
}
else if (selection2 == true)
{
theState = States.state_4;
}
}
void state_3()
{
EventSystem.current.SetSelectedGameObject(null);
theMainText.text = "something really bad happens";
buttonText1.text = "option1";
buttonText2.text = "option2";
}
void state_4()
{
EventSystem.current.SetSelectedGameObject(null);
theMainText.text = "something really good happens";
buttonText1.text = "option1";
buttonText2.text = "option2";
}
}
Your help will be immensely appreciated. Thank you!