I’m trying to create a cross pattern explosion with this code, the point is that if the fire hits a wall then I want to break out of the for loop to stop more objects being created in that axis, the next loop should still execute normally, my problem is that it doesn’t I know the trigger even is called because the object on top of the wall gets deleted, but the variable stat is not changed and the for loop resumes and every element is created.
public void explode(Vector3 fpos)
{
stat = true;
//x axis +
for (int i = 0; i < xplodrange + 1; i++)
{
if (stat)
{
rpos = new Vector3(fpos.x + i, 0.75f, fpos.z);
Instantiate(this, rpos, Quaternion.identity);
}
else
{
break;
}
}
stat = true;
//x axis -
for (int i = 0; i < xplodrange + 1; i++)
{
if (stat)
{
rpos = new Vector3(fpos.x - i, 0.75f, fpos.z);
Instantiate(this, rpos, Quaternion.identity);
}
else
{
break;
}
}
stat = true;
//z axis +
for (int i = 0; i < xplodrange + 1; i++)
{
if (stat)
{
rpos = new Vector3(fpos.x, 0.75f, fpos.z + i);
Instantiate(this, rpos, Quaternion.identity);
}
else
{
break;
}
}
stat = true;
//z axis -
for (int i = 0; i < xplodrange + 1; i++)
{
if (stat)
{
rpos = new Vector3(fpos.x, 0.75f, fpos.z - i);
Instantiate(this, rpos, Quaternion.identity);
}
else
{
break;
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("wall"))
{
stat = false;
Destroy(gameObject);
}
}