- Home /
How to start animation after dialogue ends a.k.a currentLine == 3
So I have a dialogue and when it is finished (hits line 3) it is destroyed. I want to start an animation after the dialogue is finished. So basically it is character that player talks to and when the dialogue is finished the character runs away. This running away is an animation that I want to play after the dialogue is destroyed after hitting line 3. So basically I want to say animation true when hitting line 3 of the dialogue.
I have tried and failed, I might be missing something.
public class ActivateTextAtLine : MonoBehaviour
{
public Animator animator2;
public TextAsset theText;
public int startLine;
public int endLine;
public TextBoxManager theTextBox;
public bool destroyWhenActivated;
// Start is called before the first frame update
void Start()
{
theTextBox = FindObjectOfType<TextBoxManager>();
if (theTextBox.currentLine == 3) //this should work ?
{
animator2.SetBool("PlayRun", true);
}
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.name =="Player")
{
theTextBox.ReloadScript(theText);
theTextBox.currentLine = startLine;
theTextBox.endAtLine = endLine;
theTextBox.EnableTextBox();
if (destroyWhenActivated)
{
Destroy(gameObject);
}
}
}
void OnDestroy()
{
}
void OnTriggerExit2D(Collider2D other)
{
theTextBox.DisableTextBox();
}
}
if I change theTextBox.currentLine == 3 to theTextBox.currentLine == 0 it works as expected at the current line 0, but somehow doesnt see the line 1,2,3 :///.
Answer by highpockets · Mar 18, 2019 at 07:36 PM
You know that the code in your Start () method is only running one time, right? So it is likely == 0 at the beginning and that’s why the condition is true when you use 0 and not working for the other lines because the condition is not being checked.. You could put it in the Update () method to check every frame. Or you could start a coroutine and use a while loop (while currentLine < 3 for example) and start your run animation when the while loop returns false
I placed the same thing on update and still nothing ://
if (theTextBox.currentLine == 3) //this should work ?
{
animator2.SetBool("PlayRun", true);
}
Ok, now I fixed it :D, so happy. turns out I had to swich to private Void update. I just dont know whats the difference between public and private except for the word meaning private and public. The dynamisc are unclear , but at the end it just works and it is good enought, thanks, can I make your comment as an answer ?
Just converted it to an answer. Thanks for asking glad it works
Your answer
Follow this Question
Related Questions
Add a bool to animator & activate by key press 1 Answer
How to start animation after object is destroyed ? 0 Answers
multi animation by pressing one button ,Multi Animation 0 Answers
Animtor Stuck 1 Answer
Double collision on "ground" tagged object results in player thinking they're in air? 1 Answer