- Home /
How do i know if a animation is finished or not ?
Hello, i have a camera animated and i need a Gui to show up when the animation is completed, how do i know if the animation is completed or not, c# here please..
Answer by Rydrako · Feb 09, 2013 at 04:49 AM
can you pls say it briely,
using UnityEngine;
using System.Collections;
public class Camera1 : $$anonymous$$onoBehaviour {
public GameObject camera1;
public GameObject maincamera;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (animation.IsPlaying = false){
camera1.SetActive = false;
maincamera.SetActive = true;
}
}
}
the camera 1 is the camera which contains animation, the script is in camera 1, so now how can i make it to camera 2
Answer by DubstepDragon · Feb 09, 2013 at 11:02 AM
You can use the yield command to determine the length of the animation. For example:
JavaScript:
animation.Play();
// Wait for the animation to have finished
yield WaitForSeconds (animation.clip.length);
C#:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
IEnumerator Example() {
animation.Play();
yield return new WaitForSeconds(animation.clip.length);
}
}
This can be used in an if statement. So if the animation finishes, do whatever you want it to do...
hello, actually the animation starts to play when the game starts, i have animated a camera, so after the animation has finished how can i switch off it and turn on the main camera
That, my friend, I remain unknowing of, unless you refer to this: http://www.unity3dstudent.com/2010/12/switching-cameras-at-runtime/ You can use it your way: Have a camera switch to another after the end of an animation - you can use a simple "if" statement. Just ask if you need further assistance, for that is my role.