using UnityEngine;

public class CameraLook : MonoBehaviour
{
    [SerializeField] private float cameraSensivity;
    [SerializeField] private float minLookDist;
    [SerializeField] private float maxLookDist;

    Vector2 touchDeltaPosition;
    float camLookDist;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        camLookDist = transform.localRotation.y;   
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0 && 
            Input.GetTouch(0).phase == TouchPhase.Moved) {

            touchDeltaPosition = Input.GetTouch(0).deltaPosition;
            camLookDist = Mathf.Clamp(camLookDist + touchDeltaPosition.x * cameraSensivity, minLookDist, maxLookDist);
            transform.localRotation = Quaternion.Euler(0f, camLookDist, 0f);
        }
    }

    
}
