unity mouse code example
Example 1: how to find the mouse position unity
Vector2 mousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Example 2: get mouse position unity
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Example 3: mouselook script unity
public float lookSpeed = 3;
private Vector2 rotation = Vector2.zero;
public void Look()
{
rotation.y += Input.GetAxis("Mouse X");
rotation.x += -Input.GetAxis("Mouse Y");
rotation.x = Mathf.Clamp(rotation.x, -15f, 15f);
transform.eulerAngles = new Vector2(0,rotation.y) * lookSpeed;
Camera.main.transform.localRotation = Quaternion.Euler(rotation.x * lookSpeed, 0, 0);
}