shooting projectile on mouse position on 2d multiplayer


I am trying to shoot a projectile in a 2D game through the mouse click position.

There are several code snippets similar to this one I am using:

if (Input.GetMouseButtonDown(0))
    Vector3 worldMousePos = Input.mousePosition;

    Vector2 direction = (Vector2)((worldMousePos - transform.position));

    // Creates the bullet locally
    GameObject bullet = (GameObject)Instantiate(
                            transform.position + (Vector3)(direction * 0.5f),

    // Adds velocity to the bullet
    bullet.GetComponent<Rigidbody2D>().velocity = direction * wpn.projectileSpeed;


The issue I am having as you can see is right here Vector3 worldMousePos = Input.mousePosition;

It should be Camera.main(Input.mousePosition) but the issue I am having is a multiplayer 2D game (I am using photon) and I dont have a Camera.main.

I have a player with a Camera object and this is a weapon manager belonging to the player.

I tried with (to get player camera) but itdidnt work.

Good day.

Camera.main in this context is a Camera component inside a Object, so you need to refear the camera component inside your camera object:<Camera>();

If helped, upvote/accept :smiley: