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

Setting Goal for Instantiated Clones

Discussion in 'Navigation' started by unity_10774177, Feb 18, 2020.

  1. unity_10774177

    unity_10774177

    Joined:
    Feb 18, 2020
    Posts:
    1
    I have an object that moves towards the player, and I wanted to be able to create more of the enemy to come towards the player. However, when I instantiate a clone, I realised that the goal isn't set and as such it stays still.


    Is there a way to add the goal into the script itself?

    public class MoveTo : MonoBehaviour
    {

    public Transform goal;
    NavMeshAgent agent;

    void Update()
    {
    {
    agent = GetComponent<NavMeshAgent>();
    }
    agent.destination = goal.position;
    }
    }