- Home /
Random Animation of gameObject Children
Hi, I am trying to apply a simple 'bouncing' animation to a list of Children objects. So to have the effect that every element moves independently. Below is the code I have developed so far. I have tried to apply just an animation to all of them without a random variable yet, but I cannot see any movement when I am running the game.
Animation[] rends;
public AnimationClip anim;
void Start()
{
rends = this.gameObject.GetComponentsInChildren<Animation>();
}
void Update()
{
Vector3 vec=transform.position;
vec.y = Random.Range(1000f, 2000f);
anim2.transform.position = vec;
foreach (Animation an in rends)
{
an.Play(anim.name);
}
}
Answer by travis_dean · Jul 22, 2016 at 06:15 PM
It's not exactly what you asked, but would simply making as script that moved itself randomly be easier? Animations aren't terribly suited for it.
Your answer
Follow this Question
Related Questions
AnimClip Curve to Animator parameter 0 Answers
Moving Player only during part of an animation 1 Answer
EDITOR: How to Change Animation Curve Colors 0 Answers
Animator Controller 2D RPG Best Practices 0 Answers
AnimationClip in local coordinates 1 Answer