Hey guys, I´m pretty new to Unity and I´m trying to create a infinite runner of sorts using the engine 2D tools.
I´m currently having a LOT of headaches regarding spawning objects in my scene, infinitely and randomly.
The basic concept is pretty simple: An infinite 2D runner (where the player is always running to the right), and, as he advances, different types of obstacles appear.
For some reason, the objects have been spawning in only one location and on top of each other, and I can´t figure out how to space them out and solve this problem.
Here follows my Spawn script:
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] obj;
public float spawnMin = 1f; //spawn aleatoriamente entre 1s
public float spawnMax = 2f; //e 2s
// Use this for initialization
void Start () {
Spawn();
}
void Spawn()
{
Instantiate(obj[Random.Range(0, obj.Length)], transform.position, Quaternion.identity);
Invoke("Spawn", Random.Range(spawnMin, spawnMax));
}
}