Yes, the code worked before this lesson.
Line 25 is
GridSystemVisual.Instance.ShowGridPosition(unit.GetMoveAction().GetValidActionGridPositionList());
The unit does have MoveAction.cs with it.
MoveAction.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveAction : MonoBehaviour
{
private Vector3 targetPosition;
[SerializeField] private Animator unitAnimator;
[SerializeField] private int maxMoveDistance =4;
Unit unit;
private void Awake()
{
unit = GetComponent<Unit>();
targetPosition = transform.position;
}
void Update()
{
float stoppingDistance = .1f;
if (Vector3.Distance(transform.position, targetPosition) > stoppingDistance)
{
Vector3 moveDirection = (targetPosition - transform.position).normalized;
float moveSpeed = 4f;
transform.position += moveDirection * moveSpeed * Time.deltaTime;
float rotateSpeed = 10f;
transform.forward = Vector3.Lerp(transform.forward, moveDirection, Time.deltaTime * rotateSpeed);
unitAnimator.SetBool("IsWalking", true);
} else
{
unitAnimator.SetBool("IsWalking", false);
}
}
public void Move(GridPosition gridPosition)
{
this.targetPosition = LevelGrid.Instance.GetWorldPosition(gridPosition);
}
public List<GridPosition> GetValidActionGridPositionList()
{
List<GridPosition> validGridPositionList = new List<GridPosition>();
GridPosition unitGridPosition = unit.GetGridPosition();
for (int x = -maxMoveDistance; x <= maxMoveDistance; x++)
{
for (int z=-maxMoveDistance; z <= maxMoveDistance;z++)
{
GridPosition offsetGridPosition = new GridPosition(x,z);
GridPosition testGridPosition = unitGridPosition + offsetGridPosition;
//checks for valid grid position
if(!LevelGrid.Instance.IsValidGridPosition(testGridPosition)) {continue;}
//checks to see if this is the same grid square the unit is currently in
if(unitGridPosition == testGridPosition){continue;}
//checks to see if the grid square is occupied
if(LevelGrid.Instance.IsGridOccupied(testGridPosition)){continue;}
validGridPositionList.Add(testGridPosition);
}
}
return validGridPositionList;
}
public bool IsValidActionGridPosition(GridPosition gridPosition)
{
List<GridPosition> validGridPositionList = GetValidActionGridPositionList();
return validGridPositionList.Contains(gridPosition);
}
}