I am running into an exception error when running the script with the destination set to the player castle gate. If I set the destination to any other valid space, the script functions fine. Upon further investigation, I noticed that the pathfinder script deactivates when the destination coordinates is set to the player gate. I don’t see any reason for this to occur.
Below is the contents of the pathfinder script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tower : MonoBehaviour
{
[SerializeField] int cost = 75;
float buildDelay = 1f;
void Start()
{
StartCoroutine(Build());
}
public bool CreateTower(Tower tower, Vector3 position)
{
Bank bank = FindObjectOfType<Bank>();
if(bank == null)
{
return false;
}
if (bank.CurrentBalance >= cost)
{
Instantiate(tower.gameObject, position, Quaternion.identity);
bank.Withdraw(cost);
return true;
}
return false;
}
IEnumerator Build()
{
foreach(Transform child in transform)
{
child.gameObject.SetActive(false);
foreach(Transform grandChild in child)
{
grandChild.gameObject.SetActive(false);
}
}
foreach (Transform child in transform)
{
child.gameObject.SetActive(true);
yield return new WaitForSeconds(buildDelay);
foreach(Transform grandChild in child)
{
grandChild.gameObject.SetActive(true);
}
}
}
}