How to do it...

We will just implement a new file:

  1. Create the class for handling vision:
using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
 
public class VisorGraph : MonoBehaviour 
{ 
    public int visionReach; 
    public GameObject visorObj; 
    public Graph visionGraph; 
} 
  1. Validate the visor object in case the component is not attached:
void Start() 
{ 
    if (visorObj == null) 
        visorObj = gameObject; 
} 
  1. Define and start building the function for detecting the visibility of a given set of nodes:
public bool IsVisible(int[] visibilityNodes) { int vision = visionReach; int src = visionGraph.GetNearestVertex(visorObj); HashSet<int> visibleNodes = new HashSet<int>(); Queue<int> queue = new Queue<int>(); queue.Enqueue(src); } ...

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.