using UnityEngine;
using System.Collections;

public class Seagull : MonoBehaviour {

    public float speed = 5;
    public GameObject fish;
    public float vx;
    public float vy;

	// Use this for initialization
	void Start () {
        fish = GameObject.Find("Fish");
	}
	
	// Update is called once per frame
	void Update () {
        vx = 0;
        vy = 0;

        var dir = transform.position - fish.transform.position;

        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        if (dir.magnitude > 5 && fish.transform.position.x < transform.position.x && fish.transform.position.y > 5)
        {
            
            transform.eulerAngles = new Vector3(0, 0, angle);
        }

        transform.position += transform.rotation * Vector3.left * speed * Time.deltaTime;

        if (transform.position.x < -30 || fish == null)
        {
            Destroy(gameObject);
        }
    }
}
