I have two paths for following. At one time there should spawn 1 object and there should be at left and right in turn (Let's say, the object spawned at right then the next one will be at left).Image for path logic
For this, I added an if clause like this:
if (PlayerPrefs.GetString("Spawn") == "Left")
{
randomInt = Random.Range(0, spawnPointsLeft.Length);
Instantiate(prefab, spawnPointsLeft[randomInt].position, Quaternion.identity);
}
and tried this kind of filter :
if (left)
{
randomInt = Random.Range(0, spawnPointsLeft.Length);
Instantiate(prefab, spawnPointsLeft[randomInt].position, Quaternion.identity);
left = false;
right = true;
}
else if (right)
{
randomInt = Random.Range(0, spawnPointsRight.Length);
Instantiate(prefab, spawnPointsRight[randomInt].position, Quaternion.identity);
left = true;
right = false;
}
Here is the problem, when I add the if clauses new spawned objects follow just left path.( Even if it spawned at right spawn point) . But when I filter for left it works well. I don't understand what is problem or what did I do wrong?
I'll be glad if you can help me :)