Quantcast
Viewing latest article 5
Browse Latest Browse All 60

CORoutine does not completely stop

Hi,

Got some code with the help of this site, but have a little problem.

When I press the applicable button, and hold it in, everything works, but if I only press the button and release it, it stops the first animation in the CORoutine (PowerUp), waits for the actual animation time to finish, but does not stop the second one (PowerUpLoop) so the PowerUpLoop keeps playing over and over.

I cannot use Animation.Stop(PowerUpLoop) with the StopCORoutine(COPowerUp()) if the button is released, otherwise I get a "InvalidCastException: Cannot cast from source type to destination type" error.

Any Ideas?

var PowerUp : String = "PowerUp"; var PowerUpLoop : String = "PowerUpLoop";

private var inTransition : boolean = false; private var isPowerUpLoop : boolean = false;

function COPowerUp() { inTransition = true; isPowerUpLoop = true; var state : AnimationState = animation[PowerUp];

state.wrapMode = WrapMode.Once;
state.speed = 1.0;
animation.Play(PowerUp);
yield new WaitForSeconds(state.length);
(animation.Play(PowerUpLoop));

inTransition = false; 

}

function Update () { var horizontal = Input.GetAxis("Horizontal"); var vertical = Input.GetAxis("Vertical");

if (Input.GetButtonDown("Power Up")) {
    StartCoroutine(COPowerUp());
    }

if (Input.GetButtonUp("Power Up")){
    animation.CrossFade("idle");
    inTransition = false;
    isPowerUpLoop = false;
    StopCoroutine(COPowerUp());
}

}


Viewing latest article 5
Browse Latest Browse All 60

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>