- Home /
I want to specify the location of spawning
i want my enemies spawn at just one of 3 areas on x axis like 0 and 2 and -2 i don't want them to spawn like -1 or 1 what should i do
code im using
public GameObject obstacle; private float startDelay = 2f; private float cloningSpeed = 0.1f; public float[] spawnRadius; void Start() { InvokeRepeating("clone", startDelay, cloningSpeed); }
void Update()
{
}
private void clone()
{
Instantiate(obstacle, new Vector3(Random.Range(-2,spawnRadius.Length),1,80), transform.rotation);
}
Answer by logicandchaos · Jan 28, 2020 at 02:07 PM
You just set the position after instantiating. Easier if you make a reference variable. GameObject go = Instantiate(obstacle, new Vector3(Random.Range(-2,spawnRadius.Length),1,80), transform.rotation); go.transform.position=new Vector3(0,0,0); //your coordinates go here
Your answer
Follow this Question
Related Questions
how would i make a spawn point when loading a scene? 0 Answers
Can't get objects from an array instantiate at spawn points in an array 0 Answers
spawn objects in random locations, check if location already taken 1 Answer
Spawning AI cars - weighted to ahead? 0 Answers
Two specific transform values instead of random int? Even distribution... 1 Answer