- Home /
playing animations randomly
as you see they all playing just like each other how can I make them to play randomly? I mean one of them plays at sprite 9, other plays at sprite 2, ..... how can do this very very very simple?
you can just record animations and assign different clips or choose random clips from animations and assign clip to the random sprite.
I want to do it with scripts.It would be very good if you show me how to do it.
nothing :), I just wonder is that possible or not, I just don't want to make other object ,I want them to play randomly :) and I don't really know how to do that.
var randomclipName = Animations[Random.Range(0, Animations.Length - 1)];
foreach (GameObject objects in SpriteGameObjects)
{
var anim = objects.GetComponent<Animation>();
anim.Play(randomclipName.name);
}
It's a little Complicated. but thanks I have to try it .
Answer by ddmarkas · Jul 26, 2017 at 12:00 PM
In the script attached to this object, you can write in the Start() function :
myAnimator.Play("Default",0,Random.value);
Answer by PersianKiller · Jul 26, 2017 at 01:40 PM
Please explain it clearer I don't get it.
it's my code but it does nothing.
If you replace "Random.Range(0,5)" by "Random.value", I think it will make the expected behavior.
$$anonymous$$ore explain dude , I'm not einstein :).
lol, I cannot say much more. Write in the script attached to the coin gameobject :
void Start()
{
GetComponent<Animator>().Play("coin",0,Random.value);
}
Tell me if this is working.
Answer by annonymushubh · Jul 26, 2017 at 01:45 PM
make a array and put all the animations on it and generate the Random number as between your array.length() and call the index number animation to play on it
Answer by Ki4Chan · Jul 26, 2017 at 03:45 PM
Your question is a little confusing. I think you don't want to start amination from starting all the time. Sometimes you want it to start from the middle or from some other point. Right?
look I have a coin that is prefab. it's animation has 10 sprites, I want to place 5 coin at the scene, then each of them play at random sprites.
I don't want all of them to play from sprite 0,1,2...9
I want one of the plays at 4,5,6... other at 9,0,1...
I think it's a little bit more Interesting if their animations won't play like eachOther. hope you get my idea.