using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationManager : MonoBehaviour {

	public Animator R;
	public Animator G;
	public Animator B;

	public float MaxDist;

	// Use this for initialization
	void Start () {
		
	}

	void SyncAnimations(Animator a1, Animator a2)
	{
        if ((a1.transform.position - a2.transform.position).magnitude <= MaxDist) 
		{
			var s1 = a1.GetCurrentAnimatorStateInfo (0);
			var s2 = a2.GetCurrentAnimatorStateInfo (0);
			if (s1.fullPathHash == s2.fullPathHash) 
			{
				a2.Play (s2.fullPathHash, 0, s1.normalizedTime);
                a2.Update(0);
			}
		}
	}
	
	// Update is called once per frame
	void Update () {

        R.Update(Time.deltaTime);
        G.Update(Time.deltaTime);
        B.Update(Time.deltaTime);

        SyncAnimations (R, G);
		SyncAnimations (R, B);
		SyncAnimations (G, B);

	}
}
