We'll be creating the graph representation class as well as a custom Vertex class:
- Create the VertexVisibility class deriving from Vertex:
using UnityEngine; using System.Collections.Generic; public class VertexVisibility : Vertex { void Awake() { neighbours = new List<Edge>(); } }
- Define the FindNeighbours function for automating the process of connecting vertices among them:
public void FindNeighbours(List<Vertex> vertices) { Collider c = gameObject.GetComponent<Collider>(); c.enabled = false; Vector3 direction = Vector3.zero; Vector3 origin = transform.position; Vector3 target = Vector3.zero; RaycastHit[] hits; Ray ray; float distance = 0f; // next step }
- Go over each object and cast a ray to validate whether it's ...