The code seems okay with the random.range to instantiate and object in a random x , but when i start the game the gameobject keeps spawning in the same position … i searched for a solution for 3 hours but i didnt find any. i already used this code an other game and it works fine but here its not
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class obstacleSpawner : MonoBehaviour {
public GameObject Obstacle;
public float Cooldown = 3;
public int X_max;
public int X_min;
private bool Allowspawning = true;
void Start () {
StartCoroutine("SpawnOBS");
}
// Update is called once per frame
void Update()
{
}
IEnumerator SpawnOBS()
{
while (Allowspawning)
{
Instantiate(Obstacle, new Vector3(Random.Range(X_min, X_max), 5.5f, 0f), Quaternion.identity);
yield return new WaitForSeconds(Cooldown);
yield return null;
}
yield return null;
}
}