Search Unity

Stopping Animation.

Discussion in 'Editor & General Support' started by CelticKnight, Feb 1, 2015.

  1. CelticKnight

    CelticKnight

    Joined:
    Jan 12, 2015
    Posts:
    378
    Hello Guys,

    I have implemented a way of starting/stopping a platform using a collider (in 3D environment) - pretty basic I know - but I have a problem stopping the animation of the "Lift". The code was given in the book "Beginning 3D Game Development" for a continually running platform thusly:

    Code (JavaScript):
    1. if(activateLift == true){
    2.         var weight = Mathf.Cos(Time.time * speed * 2* Mathf.PI) *0.5 + 0.5;
    3.         transform.position = targetA.transform.position * weight + targetB.transform.position * (1 - weight);
    4.         }//-->end if
    So when I stop (or start) the animation it stops it much like "Lap time" on a stopwatch. It seems that Time.time is the culprit here in that it's continually counting up from the start of the game. But I don't know enough about coding or unity to have the animation start or stop dead.

    So to anyone who is willing to help here is a big thankyou in advance.