HELP!! Animation wont reverse..

Hi all,

followed the forums & answers, but i still could get it run animation in reverse... animation was done in unity, everytime i run, it would only run the 1st step, then when i click again, supposely it should reverse but it repeated again...

any ideas anyone?

Thanks

animation.Stop();

function Update ()
{

    if (Input.GetMouseButtonDown(0))
    {
        var hit : RaycastHit;
        var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, hit))
        {
            hit.collider.gameObject.animation["slot1"].time=0.0;
            hit.collider.gameObject.animation["slot1"].speed=1.0;
            hit.collider.gameObject.animation.Play ("slot1");
            //hit.collider.gameObject.animation.Stop ("slot1");

            Debug.Log("open "+hit.collider.name);
        }
    }

    else if (Input.GetMouseButtonDown(0))
    {

        //if (Physics.Raycast(ray, hit))
        //{

            hit.collider.gameObject.animation["slot1"].speed=-1.0;
            hit.collider.gameObject.animation["slot1"].time = hit.collider.gameObject.animation["slot1"].length;
            hit.collider.gameObject.animation.Play("slot1");
            //hit.collider.gameObject.animation["slot1"].time=0;
            //hit.collider.gameObject.animation["slot1"].speed=1;
            //hit.collider.gameObject.animation.Play ("slot1");
            Debug.Log("close "+hit.collider.name);

        //}

    }
    }

You're testing for the same mouse event in the same frame. I think you need a boolean or something, toggle that, and depending on current value, run the anim forward or backward.

Something like this:

var forward = true;
function Update ()
{

    if (Input.GetMouseButtonDown(0)) // user has pressed left mouse button
    {
        var hit : RaycastHit;
        var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, hit)) // hit object
            forward = !forward;  // reverse direction

        if (forward)
        {
            hit.collider.gameObject.animation["slot1"].time=0.0;
            hit.collider.gameObject.animation["slot1"].speed=1.0;
            hit.collider.gameObject.animation.Play ("slot1");
            Debug.Log("open "+hit.collider.name);
        }
        else // backward
        {
            hit.collider.gameObject.animation["slot1"].speed=-1.0;
            hit.collider.gameObject.animation["slot1"].time = hit.collider.gameObject.animation["slot1"].length;
            hit.collider.gameObject.animation.Play("slot1");
            Debug.Log("close "+hit.collider.name);

        }
  }