Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question AI follow player Netcode Unity

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

  1. bobdabuilder2

    bobdabuilder2

    Joined:
    Dec 18, 2020
    Posts:
    2
    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()
    }
    myAgent.SetDestination(enemyTarget.position);
    {
    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?
    Thanks