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

public class Pivot : MonoBehaviour
{

    public GameObject myPlayer;

    private void Update()
    {

        Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;

        if (myPlayer.transform.localRotation.y == 0)
        {



            difference.Normalize();


            float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;

            rotationZ = Mathf.Clamp(rotationZ, -45, 45);

            transform.rotation = Quaternion.Euler(0f, 0f, rotationZ);
        } else if (myPlayer.transform.localRotation.y == 180)
        {



            difference.Normalize();


            float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;



            rotationZ = Mathf.Clamp(rotationZ, -135, 135);
            transform.rotation = Quaternion.Euler(180f, 180f, rotationZ);
        }

        









    }





}