The CrowdAgent component is incredibly simple, but gets the job done. As mentioned earlier, Unity does most of the heavy lifting for us. The following code gives our CrowdAgent a destination:
using UnityEngine; using System.Collections; [RequireComponent(typeof(NavMeshAgent))] public class CrowdAgent : MonoBehaviour { public Transform target; private NavMeshAgent agent; void Start () { agent = GetComponent<NavMeshAgent>(); agent.speed = Random.Range(4.0f, 5.0f); agent.SetDestination(target.position); } }
The script requires a component of type NavMeshAgent, which it assigns to the agent variable on Start(). We then set its speed randomly between two values for some added visual variety in our simulation. Lastly, ...