Other
Calling functions that needs to be on update()
So I have a function for a Dialogue System that changes the line on the dialogue box whenever you click. Which means it has to be in update(). My test works so far but my next problem is how to make the whole dialogue box only appear whenever I click on a character.
I tried making the characters as buttons and it does make the dialogue box show up whenever clicked, but it won't change the dialogue lines because that function has to be in an update method.
I'm looking at OnMouseDown() right now but the result will be probably the same. Any ideas?
Answer by highpockets · Dec 08, 2020 at 08:02 PM
It would be handy to see your code, but your dialogue functionality can surely be abstracted away from the Update function and if you must call it from Update you still could while still being able to call it from anywhere else:
void Update()
{
//call Dailogue in here
Dialogue();
}
void OnMouseDown()
{
//call Dialogue in here
Dialogue();
}
void Dialogue()
{
//dialogue stuff
}
public void DialogueRun()
{
dialogueBox.SetActive(true);
dialogue.text = textLine[nextLine];
//if counter is less than total lines
if (nextLine < textLine.Length - 1)
{
//change the line when clicked
if (Input.GetKeyDown(KeyCode.$$anonymous$$ouse0))
{
nextLine += 1;
}
}
else
{
dialogueBox.SetActive(false);
return;
}