- Home /
Question by
phatpixels · Jun 03, 2014 at 10:07 AM ·
animationrandom.rangecounting
Is it possible to count Random.range animation playback??
Is there a way to count actual specific animation playback? Adding Count+1; the counter just adds and climbs as fast as the random generates, not timed with the animation actually playing. Any scripts, ideas, links will be much appreciated at this stage.Thankyou all.
pragma strict
var Anims = ["up","down"];
var Model: GameObject;
function Update () {
}
Game();
}
function Game () {
var random:int = Random.Range(0,2);
if (random ==0){
animation.PlayQueued("up");
}
if (random ==1){
animation.PlayQueued("down");
}
}
Comment
Best Answer
Answer by NoseKills · Jun 03, 2014 at 06:16 PM
You could use Animation Events and a script like this. Make an animation even trigger "DoneAnimating"
#pragma strict
var Anims = ["up","down"];
var Model: GameObject;
var animating : System.Boolean;
function Update ()
{
Game();
}
function Game ()
{
if (!animating)
{
var random:int = Random.Range(0,2);
if (random == 0)
{
animation.PlayQueued("up");
animating = true;
}
else if (random == 1)
{
animation.PlayQueued("down");
animating = true;
}
}
}
function DoneAnimating()
{
animating = false;
}
Fantastic. You made me investigate the Animation Events tutorial, and after a bit of trial and error i think i can make this work with duplicates of my imported legacy animations. Thankyou :]