Hello! I’m currently trying to develop a “Choose your own adventure” text game.
This is a screenshot of the game:
It is going to have a lot of choices and branching stories depending on the choices you make.
Something like this:
Is it possible to develop a game like this using only 1 scene? I tried in many different ways but can’t seem to get it to work.
1 Answer
1
Yeah, it’s possible. I would create two scripts: One to store references of the UI components and another script that would act as a story node. The node would contain the text for the message and buttons. Clicking on a button would update the text on the UI components. Nodes would be linked to other nodes.
Example:
using UnityEngine.UI;
public class TextAdventureGui : MonoBehaviour {
public Text m_text;
public Button m_button1;
public Button m_button2;
public TextAdventureNode firstNode;
public void Start()
{
ShowNode(firstNode);
}
void ShowNode(TextAdventureNode node)
{
m_text.text = node.m_text;
m_button1.GetComponentInChildren<Text>().text = node.m_button1Text;
m_button2.GetComponentInChildren<Text>().text = node.m_button2Text;
m_button1.onClick.RemoveAllListeners();
m_button2.onClick.RemoveAllListeners();
m_button1.onClick.AddListener(()=>ShowNode(node.m_nextNode1));
m_button2.onClick.AddListener(()=>ShowNode(node.m_nextNode2));
}
}
.
using UnityEngine.UI;
public class TextAdventureNode : MonoBehaviour {
public string m_text;
public string m_button1Text;
public string m_button2Text;
public TextAdventureNode m_nextNode1;
public TextAdventureNode m_nextNode2;
}
So i need to make different scripts for every node? I'm going to end up with lots of scripts if I do that.
– Vento313After some testing I managed to make a version of the game that works with a similar script. Thanks for the input!
– Vento313