using UnityEngine;
using System.Collections;

public class CharAnimationTiming : MonoBehaviour {

    public Animator[] charAnimations;
    public Animator[] crowdAnimations;
    public FixAudienceColor[] dummy;

    private void Awake()
    {
        //GetCrowdReference
        GetCrowdReference();
        TimeAnimation();
    }
    private void GetCrowdReference()
    {
        crowdAnimations = new Animator[dummy.Length * 20];
        for (int i = 0; i < dummy.Length; i++)
        {
            Animator[] dummy2 = dummy[i].transform.GetComponentsInChildren<Animator>();
            for (int j = 0; j < dummy2.Length; j++)
            {                
                crowdAnimations[i * dummy2.Length + j] = dummy2[j];
            }
        }
    }
    private void TimeAnimation()
    {

        //character animation
        int[] order = new int[charAnimations.Length];
        for (int i = 0; i < order.Length; i++)
        {
            order[i] = i;
        }
        GameManager.Shuffle(ref order);
        for (int i = 0; i < charAnimations.Length; i++)
        {
            charAnimations[order[i]].Play("prancha_floating", -1, i * 0.25f);
        }

        //crow animation
        float[] normalTimes = { 0f, 0.25f, 0.5f, 0.75f };
        for (int i = 0; i < crowdAnimations.Length; i++)
        {
            crowdAnimations[i].Play("people_idle", -1, normalTimes[Random.Range(0, normalTimes.Length)]);
        }
    }

}
