I’m trying to get a prefab to detect a player object with the name “FPSController” but it can’t find it. The object is definitely active and the rest of the script works without the GameObject.Find, but I can’t declare that in the prefab, any help is greatly appreciated. Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NavMesh : MonoBehaviour
{
private Transform PlayerPos;
private GameObject player;
private NavMeshAgent navMeshAgent;
void Start(){
}
void Awake(){
navMeshAgent = GetComponent<NavMeshAgent>();
PlayerPos = player.GetComponent<Transform>();
player = GameObject.Find("FPSController");
}
void Update() {
navMeshAgent.destination = PlayerPos.position;
}
}