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);

        }

    }

1 Answer

1

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.