using UnityEngine;
using System.Collections;

public class KitchenDog : MonoBehaviour {

	public Transform target;
	bool move = false;
	Animator anim;
	Room room;
	// Use this for initialization
	void Start () {
		anim = GetComponent<Animator>();
		room = FindObjectOfType<Room>();
	}
	
	// Update is called once per frame
	void Update () {
		if(move){
			if(transform.position.x< target.position.x){
				transform.position+=Time.deltaTime*Vector3.right;
			} else {
				move = false;
			}
		}
	}

	void Enter(){
		move = true;
	}

	void OnTriggerEnter2D(){
		StartCoroutine(Mount ());
	}

	IEnumerator Mount(){
		anim.SetBool ("lick",true);
		yield return new WaitForSeconds(1);
		room.player.SendMessage ("GetDog");
		Destroy(GameObject.Find ("Dog"));
	}
}
