- Home /
Question by
Speshimen · Jun 12, 2017 at 09:03 AM ·
2dscripting probleminstantiationrandomspawning
Instantiating an object randomly withing the boundaries of an object.
Im trying to spawn an object called Asteroid in a random location within the boundaries of the green area with an interval. I can't figure out what i'm supposed to write in the Instantiation code. Could someone please help me?
public class SpawnerScript : MonoBehaviour {
public float SpawnRate = 3;
private float NextSpawn;
public GameObject Asteroid;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Time.time > NextSpawn)
{
NextSpawn = Time.time + SpawnRate;
Instantiate(Asteroid,???
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612123912im_/https://answers.unity.com/themes/thub/images/avi.jpg)