Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question AI follow player Netcode Unity

Discussion in 'Netcode for GameObjects' started by bobdabuilder2, Dec 2, 2022.

  1. bobdabuilder2


    Dec 18, 2020
    Hello, I made a NavMeshAgent Ai that follows a player around the scene, but ever since I started using the Unity Netcode for GameObjects, the AI wont follow the player around because the NetworkManager uses a playerPrefab and once the prefab is spawned in, the manager creates a clone of the player. The AI is set to follow the original player prefab not the clone made by the NetworkManager.
    Here is my code:

    public Transform enemyTarget;

    protected NavMeshAgent myAgent;

    void Start()
    myAgent =GetComponent<NavMeshAgent>();

    void Update()
    Can anyone help me out with creating a code that will allow the AI to follow the player Prefab clone that the NetworkManager spawns in the scene?