Raycast player detect

I’m trying to make a simple fighting game.
I figured I’d use Raycast to check if the opponent is in range, but I encountered a problem. My Raycast can’t detect the other player.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
 
public class player_1 : MonoBehaviour {

public float reach = 2;
public bool inRange = false;
 
void FixedUpdate ()
    {
RaycastHit hit;
        Ray punchRay = new Ray (transform.position, Vector3.right * reach);
 
        Debug.DrawRay (transform.position, Vector3.right * reach);
 
        if (Physics.Raycast (punchRay, out hit, reach)) {
            if (hit.collider.gameObject.tag == "player_2")
               inRange = true;
        }
}
        }

Hope you can help.

i dont see anything wrong with the script

you could try
to check if the other object has an collider
also try to
put debug.log(hit.collider.gameObject.name);
after you shoot the raycast it will put the name of the object you hit in the log maybe youre hitting yourself

hope this helps