I'm making an endless runner game.
I have the script that make coins and walls appear at the same time in front of the player.
The problem is that sometimes the coin and wall appear in the same place/position.
How can I ensure that coins and walls do not appear in the same place/position?
public class Instantiate : MonoBehaviour
{
public float betweenSpawn = 1.05f;
public float angle;
public Vector3 spawnValues; //Range of appearing
public GameObject coinPrefab;
public GameObject wallPrefab;
public Transform coinInstantiate;
public Transform wallInstantiate;
void Start()
{
InvokeRepeating("Spawn", 0f, betweenSpawn);
}
void Spawn()
{
Vector3 coinPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), 1, Random.Range(-spawnValues.z, spawnValues.z));
Vector3 wallPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), 1, Random.Range(-spawnValues.z, spawnValues.z));
Instantiate(coinPrefab, coinPosition + coinInstantiate.TransformPoint(0, 0, 0), Quaternion.AngleAxis(angle, Vector3.forward));
Instantiate(wallPrefab, wallPosition + wallInstantiate.TransformPoint(0, 0, 0), Quaternion.AngleAxis(angle, Vector3.forward));
}
}