I am making a tower defense game and i come to the problem when coming to path finding.
I made roadblocks to be placed on the field to block the path and the enemies are nav mesh agents but i don’t want the player to completely block off the road. I created a script to destroy any block if it block every way to the end. It was successful but i can place the block that block the way but not other blocks after i blocked the way. My script for the nodes to place block
GameObject turretToBuild = buildManager.instance.GetTurretToBuild();
turret = (GameObject)Instantiate(turretToBuild, transform.position + offset, transform.rotation);
Debug.Log(“Object Instansiated”);
if (turret.transform.GetChildCount() != 0)
{
Renderer renderer = turret.transform.FindChild(“range”).gameObject.GetComponent();
renderer.enabled = false;
}
Agent.calPath();
if (Agent.pathValid() == false)
{
Debug.Log(“Can’t Build Here”);
Destroy(turret);
return;
}
Scripts for the agents
public static bool pathValid()
{
NavMesh.CalculatePath(itself.position,tran.position,NavMesh.AllAreas,path);
if(path.status == NavMeshPathStatus.PathPartial)
{
Debug.Log(“path imcomplete”);
return false;
}
else {
return true;
}
}
I don’t know why it happened. Please answer thank you