- Home /
Objects move down from top of screen,I want objects to randomly spawn at the top
hey guys i need help with something. I want object to spawn at random positions at the top of the screen and move down to the bottom but sometimes randomly change lanes instead of going down in one direction. ,Hey guys I need help with something... I want different objects to spawn at the top of the screen and move towards the bottom of the screen and randomly change directions instead of moving straight down.
Where is your code? Try to code it, if you don’t know where to begin, I suggest tutorials.
Answer by logicandchaos · Aug 26, 2020 at 12:27 AM
use Random.Range to generate random numbers, you can use them for spawn locations and for moving too. you can make a random number from -1 to 1 so -1 makes it go left down, 0 straight down, 1 right down. or whatever you need.
Answer by Llama_w_2Ls · Aug 26, 2020 at 09:34 AM
So basically like...
public GameObject CubeToSpawn;
int RandomX;
void Update()
{
GameObject spawnedCube = Instantiate(CubeToSpawn, new Vector3(RandomX, 6, 0), Quaternion.identity);
StartCoroutine(Delay());
}
IEnumerator Delay()
{
yield return new WaitForSeconds(1);
}
And in the update() sorry i missed to write at the beginning RandomX = UnityEngine.Random.Range(-2, 2)
Your answer
Follow this Question
Related Questions
Is the map of this game fixed or randomly generated? 1 Answer
Problem with Auto instantiating in X seconds in C# 1 Answer
how to generate custom procedural terrain ? 0 Answers
Help with flappy bird random spawn 2 Answers
Random Map generation like Temple run,Random Map generation like Temple Run. 0 Answers