Raycasting isn't working anymore (C#)

Hello, a raycast in my game isn’t working anymore, it was working lately before but I don’t know what happened, and I didn’t change anything in it.

void Update ()
    	{
    		RaycastHit RayHit;
    		Ray ShootRay = new Ray (transform.position, Vector3.forward);
    
    		if (Input.GetKey (Keycode.Y))
    		if (allweapons.weapon == true)
    		if (Physics.Raycast(ShootRay, out RayHit))
    		if (RayHit.collider.gameObject.name == OpponentPlayer.name)
    		{
    			Debug.Log ("Shooting" + OpponentPlayer.name);
            }

Any help would be useful, thanks in advance

Try:

void Update (){
   if (Input.GetKey (Keycode.Y))
      if (allweapons.weapon == true){

          RaycastHit RayHit = Physics.Raycast(transform.position, Vector3.forward,Mathf.Infinity);

         if(RayHit)
           if (RayHit.collider.gameObject.name == OpponentPlayer.name)
           {
              Debug.Log ("Shooting" + OpponentPlayer.name);
           }
       } 
    }