I want the for loop in the code below to run again after it has finished. How do I do that? I never really understood the uses of return, continue, and break.
if(path.path.Count > this.gameObject.GetComponent<EnemyCombat>().actionPoints)
{
target = (Vector3)path.path[this.gameObject.GetComponent<EnemyCombat>().actionPoints].position;
path = seeker.StartPath (this.gameObject.transform.position, target, null);
yield return StartCoroutine(path.WaitForPath());
for(int i = 0; i < initiativeRollScript.combatants.Count; i++)
{
if(target == initiativeRollScript.combatants*.transform.position)*
-
{*
_ Vector3 tempTarget = initiativeRollScript.combatants*.transform.position;_
_ tempTarget.x += Random.Range(-1,1);_
_ tempTarget.z += Random.Range(-1,1);_
_ target = tempTarget;_
_ }_
_ }_
_ path = seeker.StartPath (this.gameObject.transform.position, target, null);_
_ yield return StartCoroutine(path.WaitForPath());_
_ }*_
The code is used in a turn based combat game I’m making. It’s designed to do two things: stop a path short if it has more nodes than the enemy has action points, and 2) find out if the shortened path lands on another combatant (enemy or player) and move to a random tile between -1and 1 on x and z that is not occupied.
At the moment, because the for loop only runs once, enemies still land on other combatants if the recalculated position is the same as a second combatant’s position. I need to keep running the for loop and change the target variable until the target location does not equal a combatant’s position.