Getting ready

This approach is very similar to the one used in the previous recipe. We must add a new member variable to our AgentBehaviour class. We should also refactor the Update function to incorporate priority as a parameter to the Agent class's SetSteering function. The new AgentBehaviour class should look something like this:

public class AgentBehaviour : MonoBehaviour 
{ 
    public int priority = 1; 
    // ... everything else stays the same 
    public virtual void Update () 
    { 
        agent.SetSteering(GetSteering(), priority); 
    } 
} 

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.