shoot with a Raycast

hi guys I need help in improving my RAYCAST I used this in turret but now I want to assign it to a soldier can anyone please help? thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class raycasting : MonoBehaviour {
public float rotationSpeed;
public float distance;
public GameObject bullet;
void Start () {
Physics2D.queriesStartInColliders = false;
}

void Update () {
transform.Rotate (Vector3.forward * rotationSpeed * Time.deltaTime);
RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance);
if (hitInfo.collider != null) {
Debug.DrawLine (transform.position, hitInfo.point);
if (hitInfo.collider.CompareTag (“friend”)) {
Instantiate (bullet, gameObject.transform.position, gameObject.transform.rotation);
}
} else {
Debug.DrawLine (transform.position, transform.position + transform.right * distance);

}
}
}

What do you need help with, exactly?
and how is this related to the physics forum? I believe this belongs to scripting.