- Home /
How to play animation clip after the conditon is finished?
i have 2 animation clip, the first one plays automatically and the dialog box plays in timer.
so how do i play the second animation when the dialog box ended, i marked the location down below in the codes.
i really dont know the code for this one. i searched for days so being desperate i came here.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextBox : MonoBehaviour {
public GameObject textbox;
public Text thetext;
public TextAsset textfile;
public string[] textline;
public int currentline;
public int endline;
void Start()
{
if (textfile != null)
{
textline = (textfile.text.Split('\n'));
}
if (endline == 0)
{
endline = textline.Length - 1;
}
}
void Update ()
{
thetext.text = textline [currentline];
if (Input.GetKeyDown (KeyCode.Space))
{
currentline += 1;
}
if (currentline > endline)
{
textbox.SetActive (false);
//IM GOING TO PUT THE CODE HERE
}
}
public void ReloadScript(TextAsset thetext)
{
if (thetext != null)
{
textline = new string[1];
textline = (thetext.text.Split('\n'));
}
}
}
Who has the animation? The textbox gameobject? The same wich is using this class?
How do you handle the animation: via Animation or Animator component?
the animation is on the other gameobject that holds camera.
i made it through Animation. the one with keys. so its a clip
Answer by Halleester · May 03, 2016 at 01:59 PM
I'm not so sure about individual animations clips, but you could create an Animator Controller with the Animation clips inside. You can then use animation transitions with bools in the animator to set up the transition to the new animation. You could then use Animator.SetBool to set the bool from the animator to true. using UnityEngine; using System.Collections; using UnityEngine.UI;
public class TextBox : MonoBehaviour {
public GameObject textbox;
public Text thetext;
public TextAsset textfile;
public string[] textline;
public int currentline;
public int endline;
public Animator anim;
void Start()
{
if (textfile != null)
{
textline = (textfile.text.Split('\n'));
}
if (endline == 0)
{
endline = textline.Length - 1;
}
}
void Update ()
{
thetext.text = textline [currentline];
if (Input.GetKeyDown (KeyCode.Space))
{
currentline += 1;
}
if (currentline > endline)
{
textbox.SetActive (false);
anim.SetBool("Variable", true);
}
}
public void ReloadScript(TextAsset thetext)
{
if (thetext != null)
{
textline = new string[1];
textline = (thetext.text.Split('\n'));
}
}
}
thanks man, and i removed the exit time and it works perfectly well
Your answer
Follow this Question
Related Questions
Animation not looping 1 Answer
Parameterized Animation Clip 0 Answers
Mirroring animation clip without mirroring root motion node? 0 Answers
Animator Override Controller changed at runtime doesn't always play the animations correctly 1 Answer
Why does my transition freeze the second animation on it's first frame? 1 Answer