Enemy Not Shooting Projectiles

I’m following a tutorial and it states that at this point, the enemy should be shooting an established projectile prefab, however, it’s not shooting at me at all and turns to avoid me like it does with the other obstacles in the scene. I’m sure it’s got something to do with the sphere cast and how it’s failing to see me as the player, but being super new to coding, I’m not sure how to go about solving the problem. I’m using C#.

`using UnityEngine;
using System.Collections;

public class WanderingAI : MonoBehaviour
{
[SerializeField] private GameObject fireballPrefab;
private GameObject _fireball;

public float speed = 3.0f;
public float obstacleRange = 5.0f;

private bool _alive;

void Start() {
	_alive = true;
}

void Update() {
	if (_alive) {

		transform.Translate (0, 0, speed * Time.deltaTime);

		Ray ray = new Ray (transform.position, transform.forward);
		RaycastHit hit;
		if (Physics.SphereCast (ray, 0.75f, out hit)) {
			GameObject hitObject = hit.transform.gameObject;
			if (hitObject.GetComponent<PlayerCharacter> ()) {
				if (_fireball == null) {
					_fireball = Instantiate (fireballPrefab) as GameObject;
					_fireball.transform.position =
						transform.TransformPoint (Vector3.forward * 1.5f);
					_fireball.transform.rotation = transform.rotation;
				}
			} else if (hit.distance < obstacleRange) {
				float angle = Random.Range (-110, 110);
				transform.Rotate (0, angle, 0);
			}
		}
	}
}

public void SetAlive(bool alive) {
	_alive = alive;
}

public void ReactToHit() {
	WanderingAI behavior = GetComponent<WanderingAI> ();
	if (behavior != null) {
		behavior.SetAlive(false);
	}
}
		


		}`

Furthermore, I can’t seem to get the code to line up correctly in this post. Is there a better way to do that rather than click on the, “Code Sample” button?

Hi, I know this is old but I had the same problem!.

If you check the code, it says:

hitObject.GetComponent<PlayerCharacter>())

The problem was I forgot to add the PlayerCharacter script to the player (just drag PlayerCharacter to the cylinder’s inspector, it should appear below FPS input and Axes scripts.