It might be a bit extreme, but where you set isFinished, could you just return;
and exit the method?
Otherwise, you will need a second boolean check.
if (!isFinished)
{
// If the level has arrived at the current destination node and not at the final node
// Destination node is based on the interpolated points on the spline
if (AtNode(catmullRomSpline.InterpolatedPoints[nodeIndex], node))
{
// If we have not reached the final node/interpolated point on spline
if (nodeIndex + 1 < catmullRomSpline.InterpolatedPoints.Count)
{
// Increase the node index
nodeIndex++;
}
else
{
return;
}
}
// Now move object unless finished is true
or;
if (!isFinished)
{
// If the level has arrived at the current destination node and not at the final node
// Destination node is based on the interpolated points on the spline
if (AtNode(catmullRomSpline.InterpolatedPoints[nodeIndex], node))
{
// If we have not reached the final node/interpolated point on spline
if (nodeIndex + 1 < catmullRomSpline.InterpolatedPoints.Count)
{
// Increase the node index
nodeIndex++;
}
else
{
isFinished = true;
}
}
// Now move object unless finished is true
if(!isFinished)
{
// Do Stuff
}
}
You have a check for "isFinished" up at the top also, is this necessary? I don't know how you're handling things outside this local block so I can't say for certain, but if you thought it may exit immediately once isFinished becomes true inside the block, that is incorrect.