Hello,
I’m newish to Unity and wanting to make a Visual Novel based game that has a dialogue system which has a choice system that also remembers certain choices as well as doing seperate dialogue for each choice.
However the way I have done it is not the best, I have the code I have below:
public string[] names;
public string[] sentences;
public Sprite[] characters;
public TextMeshProUGUI nameDisplay;
public TextMeshProUGUI dialogueDisplay;
public Image characterBox;
public GameObject continueButton;
public AudioSource audioSource;
public float typingSpeed;
private int index;
void Start()
{
audioSource.Play();
StartCoroutine(Type());
nameDisplay.text = names[index];
characterBox.sprite = characters[index];
}
void Update()
{
if(dialogueDisplay.text == sentences[index])
{
continueButton.SetActive(true);
audioSource.Stop();
}
if (Input.GetMouseButton(0))
{
typingSpeed = 0.005f;
} else
{
typingSpeed = 0.02f;
}
}
IEnumerator Type()
{
foreach(char letter in sentences[index].ToCharArray())
{
dialogueDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSentence()
{
audioSource.Play();
continueButton.SetActive(false);
if(index == sentences.Length - 1)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
if(index < sentences.Length - 1)
{
index++;
dialogueDisplay.text = "";
nameDisplay.text = "";
nameDisplay.text = names[index];
characterBox.sprite = characters[index];
StartCoroutine(Type());
} else
{
dialogueDisplay.text = "";
nameDisplay.text = "";
nameDisplay.text = names[index];
characterBox.sprite = characters[index];
continueButton.SetActive(false);
}
}
How would I start on a system that would allow for choices that trigger and get remembered, as well as choices leading to different dialogue paths. What’s the best route for this?