The TestCode class

The TestCode class will use the AStar class to find the path from the start node to the target node, as shown in the following code from the TestCode.cs file:

using UnityEngine; 
using System.Collections; 
 
public class TestCode : MonoBehaviour { 
  private Transform startPos, endPos; 
  public Node startNode { get; set; } 
  public Node goalNode { get; set; } 
 
  public ArrayList pathArray; 
 
  GameObject objStartCube, objEndCube; 
  private float elapsedTime = 0.0f; 
  //Interval time between pathfinding 
  public float intervalTime = 1.0f; 

In the preceding snippet, we first set up the variables that we need to reference. The pathArray variable stores the nodes array that's returned from the AStar FindPath method.

In the following code block, we ...

Get Unity Artificial Intelligence Programming - Fourth 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.