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

public class EyeScript : MonoBehaviour {

    public GameObject brokeneye;

    public void FixedUpdate()
    {
        //transform.Rotate(new Vector3(0, 0, 1));
        Vector3 playerpos = GameObject.Find("player").transform.position;
        Vector3 dir = (playerpos - transform.position).normalized;
        float angle = Mathf.Atan2(dir.y, dir.x);
        if (GetComponent<Rigidbody2D>().isKinematic)
            transform.rotation = Quaternion.Euler(0, 0, angle/Mathf.PI*180-185);
        else
        {
            float rot = transform.rotation.eulerAngles.z;
            GetComponent<Rigidbody2D>().AddTorque(rot - angle);
        }
    }

    private void OnDestroy()
    {
        GameObject.Find("QuestTracker").GetComponent<QuestTrackerScript>().Did(1);
        GameObject.Instantiate(brokeneye, transform.position - Vector3.up*4, Quaternion.identity);
        GameObject eggz = GameObject.Find("eggplace");
        eggz.transform.position = transform.position;
    }
}


