Getting ready

In this recipe, we will combine two concepts into a class. First, tagging a vertex to represent that fact that it's owned by a faction; second, the drop-off function from units. Such a class is called Guild. This is a component to be attached to the game object; one component for each desired guild:

using UnityEngine; 
using System; 
using System.Collections; 
 
public class Guild : MonoBehaviour 
{ 
    public string guildName; 
    public int maxStrength; 
    public GameObject baseObject; 
    [HideInInspector] 
    public int strenghth 
 
    public virtual void Awake() 
    { 
        strength = maxStrength; 
    } 
}

It also needs a drop-off function. This time, however, we wanted to create an example using Euclidean distance:

public virtual float GetDropOff(float distance) ...

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.