Raycasting From an Object to a Mouse Click Point

I’m trying to write a simple script to cast a ray from a gun object to whatever object/point the player clicks on. Right now, it doesn’t show any errors, but it doesn’t draw the ray or give me the debug.log message it’s supposed to. Here is the code:

void Update () 
{
if(Input.GetMouseButtonDown(0))
{
	
	RaycastHit hitInfo;
	
	if (Physics.Raycast(transform.position, Vector3.forward, out hitInfo, range))
	{
		Debug.Log("You are shooting");
		Debug.DrawRay(transform.position, hitInfo.point);
	}
}

it is not giving you message because it is not colliding with anyone.

try this to check at where you are raycasting. and make sure you are raycasting it into right direction.

    void Update ()
    {
    Debug.DrawRay(transform.position, Vector3.forward);
    if(Input.GetMouseButtonDown(0))
    {
     
    RaycastHit hitInfo;
     
    if (Physics.Raycast(transform.position, Vector3.forward, out hitInfo, range))
    {
    Debug.Log("You are shooting");
    Debug.DrawRay(transform.position, hitInfo.point);
    }
    }