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