Input.GetMouseButtonDown never returns true

So this is really wierd but whenever i try to put down a beutifull Input.GetMouseButtonDown it never works…
ive never encountered something like this before and its kinda a pain but i cant seem to fix it. and if i print the output it always says false.

my code looks something like this

private void Update()
    {
       
        if (cursor != null && Camera.current != null)
        {
            var x = Camera.current.ScreenToWorldPoint(Input.mousePosition);
            Vector2Int pos = new Vector2Int(Mathf.RoundToInt(x.x), Mathf.RoundToInt(x.y));
            cursor.position = new Vector3(pos.x, pos.y, transform.position.z);

            if (Input.GetMouseButtonDown(0))
            {
                print("omg");
            }

        }
    }

Thanks for any help

Use Camera.main instead of Camera.current. And make sure your camera is actually tagged MainCamera

1 Like

Thank you so much for the help… mind explaining why that worked for future reference because i really thought it wouldnt but it did.

It’s very unusual to use Camera.current and so I’m surprised you’ve not encountered the problem earlier.

When to use Camera.current can be found here.

Camera.current is only set during rendering and could change depending on the context. You should not use it in Update which is pre-rendering. Also Camera.current could even reference the internal camera of the scene view inside the editor, again all depending on the context. In multi-camera rendering setups (like VR) Camera.current may reference either the left or right eye, again depending on the context.

So as @zulo3d said, in most cases you would use Camera.main or setup a public Camera variable and assign the camera you want to use.