I’m making this game where a cube goes forward on a platform, and it has to dodge the obstacle (which are others cube) that are generated in a random way:
public class BlockSpawner : MonoBehaviour
{
public Transform[] spawnPoints;
public GameObject blockPrefab;
public float timeBetweenWaves = 1f;
private float timeToSpawn = 2f;
// Update is called once per frame
void Update()
{
if(Time.time >= timeToSpawn)
{
SpawnBlock();
timeToSpawn = Time.time + timeBetweenWaves;
}
}
void SpawnBlock()
{
int randomIndex = Random.Range(0, spawnPoints.Length);
for (int i = 0; i < spawnPoints.Length; i++)
{
if (randomIndex != i)
{
Instantiate(blockPrefab, spawnPoints*.position, Quaternion.identity);*
}
}
}
}
at the start, my problem was that the block spawners didn’t move, so I made that the block spawners follow the player but 100z before it. Now the new problem is that the obstacle spawners change their X and fell off the platform, how do I fix their X position even when the player is moving right and left?