using UnityEngine;
using System.Collections;

public class AnimatedCameraController : MonoBehaviour {
	Animator cameraAnimator;
	public float cameraMoveLeftTime = 1;
	public float cameraRecordLeftTime = 1;
	public float cameraMoveRightTime = 1;
	public float cameraRecordRightTime = 1;
	public AudioClip audioClip;
	private AudioSource audio;
	
	// Use this for initialization
	void Start () {
		cameraAnimator = gameObject.GetComponent<Animator>();
	
		audio = gameObject.GetComponent<AudioSource>();
		audio.clip = audioClip;
		StartCoroutine(CameraService());
	}
	
	IEnumerator CameraService()
	{
		while(true)
		{
			cameraAnimator.SetInteger("State", 0);
			
			yield return new WaitForSeconds(cameraMoveLeftTime);
			audio.Play();
			cameraAnimator.SetInteger("State", 1);
			yield return new WaitForSeconds(cameraRecordLeftTime);
			cameraAnimator.SetInteger("State", 2);
			
			yield return new WaitForSeconds(cameraMoveRightTime);
			audio.Play();
			cameraAnimator.SetInteger("State", 3);
			yield return new WaitForSeconds(cameraRecordRightTime);
		}
	}
}
