- Home /
Animation not working
Hi ,
I am trying to play an animation on third person controller but doesn't seems to work properly , it starts to repeat itself like its in a loop.
Following is what i tried-
using UnityEngine;
using System.Collections;
public class AnimationButton : MonoBehaviour {
public GameObject testObject1;
public GameObject testObject2;
public AnimationClip frontToBack;
public bool check = false;
Rect button1Area = new Rect (200, 0, 110, 20);
// Use this for initialization
void Start () {
animation["FrontToBack"].wrapMode = WrapMode.Once;
if(testObject1.active == true){
testObject2.active = false;
}
}
// Update is called once per frame
void Update () {
if (check == true) {
animation.Play ("FrontToBack");
}
}
void OnGUI () {
if (GUI.Button (button1Area, "To Back Door")) {
if (testObject1.active == true) {
check = true;
}
}
if (animation.IsPlaying ("FrontToBack")) {
Debug.Log ("Playing");
}
}
}
I understand it will stop once the Boolean value is FALSE but how can i determine the animation has played once ?
Answer by GraviterX · Jun 04, 2014 at 02:33 AM
First, select the animation. Then look in the inspector for the "wrap mode" button. Set this to once. The animation should play once.
I don't see warp mode in 4.3.1. If you have a later version look for "Loop Time" in the Inspector.
Your answer
Follow this Question
Related Questions
Button animation state stays Pressed or Highlighted after disabling GameObject 0 Answers
issue rendering animation on button click 1 Answer
Distribute terrain in zones 3 Answers
How do I trigger an animation using a button? 3 Answers
Animator.Update High CPU Usage on Unity 5 resulting in bugs on Android 0 Answers