Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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