- Home /
I am attempting to play an animation in reverse and slow it down, But it only seems to play forwards.
Hello,
I currently have an animation play based on the transform of an GameObject(background). The animation plays when the object is at the correct transform. But what I cannot get it to do it to play the animation in reverse when it reaches the other end. I have seen on other questions that using a negative speed would get it to move in the reverse direction. But this does not seem to be the case, can anyone help me?
Here is the code I have been using.
using UnityEngine;
using System.Collections;
public class CameraMenu : MonoBehaviour {
public GameObject background;
public Transform backgroundpos;
public Animation MoveLeft;
public float PlaySpeed = 0.01F;
// Use this for initialization
void Start ()
{
backgroundpos = background.transform;
}
// Update is called once per frame
void Update ()
{
if(backgroundpos.position.x == 18)
{
animation.Play("MoveLeft");
animation["MoveLeft"].speed = PlaySpeed;
}
if(backgroundpos.position.x == -18)
{
animation.Play("MoveLeft");
animation["MoveLeft"].speed = -PlaySpeed;
}
}
}
Thank you in advance
Jack Perry
Answer by jimmycrazyskills · Feb 20, 2014 at 07:08 PM
Sorry if wrong , but I think you need to set the play speed before playing the clip , so try switching the two lines of code.
animation["MoveLeft"].speed = -PlaySpeed;
animation.Play("MoveLeft");
Can set speed on the fly. One cute trick is ["walk"].speed = velocity.magnitude;
every frame, so that Walk is always the correct pace.
Answer by Owen-Reynolds · Feb 20, 2014 at 09:51 PM
Not sure how the background is moving, and how it gets to 18 or -18, but, checking ==
is likely the problem. Try <=-18
and '>=18'.
Computer numbers round funny, since they're really ten or so binary digits. If you add 0.1 ten times, you might get 0.9999999 or 1.000000001. So, if might be 17.900001 and jump past 18 to 18.00001. It's sort of like saying you want someone six feet tall. Not to the nearest inch, exactly six feet using lasers and GPS. You won't find anyone.
Adding +1 over and over is fine. Computers aren't goal junk. The problems are only when you use fractions. Think of how we have to write 1/3rd as 0.333333.
Your answer
Follow this Question
Related Questions
Animation Stop and Stay 1 Answer
Animation ["1"].speed = 0; Doesn't work 2 Answers
Creating a play/pause button for animations. 0 Answers
[Unsolved] Playing animation backwords [Unsolved] 1 Answer
GUITexture touch play animation 0 Answers