Please help, why? Input.mouse.mouseposition is doesn't work in side the game window but works outside?

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

public class Rotatate : MonoBehaviour
{

void Update()
{
    Vector3 gunpos = Camera.main.ScreenToViewportPoint(Input.mousePosition);
    if (gunpos.x < transform.position.x)
    {
        transform.eulerAngles = new Vector3(transform.rotation.x, 180f, transform.rotation.y);

    }

    else
    {
        transform.eulerAngles = new Vector3(transform.rotation.x, 0f,transform.rotation.z);
    }

}

}

Video : Reddit - Dive into anything

I’m no expert, but I think you should be using screen to world point.