FPS shooting

Hi! I’m currently making a 3D FPS game.

public PlayerWeapon weapon;

[SerializeField]
private Camera cam;

[SerializeField]
private LayerMask mask;

void Start()
{
    if (cam == null)
    {
        Debug.LogError("PlayerWeapon: No camera referenced!");
        this.enabled = false;
    }
}

void Update()
{
    if (Input.GetButtonDown("Fire1"))
    {
        Shoot();
    }
}

void Shoot()
{
    RaycastHit hit;
    if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, weapon.range, mask))
    {
        // We hit something
        Debug.Log("We hit " + hit.collider.name);
    }
}

&

[System.Serializable]
public class PlayerWeapon
{
public string name = "Glock";

public float damage = 10f;
public float range = 100f;
}

These are my codes related to shooting. However, When I run the program, and click fire, nothing comes out on my console. How should I fix it???

Make sure you have assigned all variables in the inspector. E.g. LayerMask.
Also, it appears that you have not obtained reference to the camera object. Consider adding this to your Start method

    cam=GetComponent<Camera>();