- Home /
Reverse animation loop stops at frame zero
Im trying to do a simple animation with my 2d sprite.
I got 20 frames in one animation state. Through a script Im controlling the speed of the animation. Hitting the right arrow Im setting the speed to 1 and the animation is looping as wanted. When Im hitting the left arrow, I set the speed to -1, so it's going reverse but it's stopping at key frame 0 and not looping back. Why?
I was trying to access to "anim.animation" but it raises an error MissingComponentException: There is no animation attached to the game object.
Anyone can help me?
using UnityEngine;
using System.Collections;
public class MyScript : MonoBehaviour {
public float speed = 1.0f;
public string axisName = "Horizontal";
public Animator anim;
// Use this for initialization
void Start () {
anim = gameObject.GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if(Input.GetAxis(axisName)<0){
anim.speed = -1;
}else if(Input.GetAxis(axisName)>0){
anim.speed = 1;
}
else{
anim.speed = 0;
}
}
}
Please post your code. Otherwise we can't help you here.
Your answer
Follow this Question
Related Questions
Transition Animations at end of current loop 0 Answers
Scissor tool with 2d sprite 0 Answers
Animation is not playing again in Unity 4.3 1 Answer
Whats the best way to handle this animation 0 Answers
Blender Animation Looping Delay Problem 2 Answers