I am making a game where red bullets are coming down on the screen at you, and I have the instantiating part done, but I can't figure out how to make them spawn at a random spot along the top of the screen. I am using Unity.
Asked
Active
Viewed 1,023 times
-2
-
Use a random number where the bounds are the edges of your screen: https://stackoverflow.com/questions/3975290/produce-a-random-number-in-a-range-using-c-sharp – Victor Chelaru Jan 25 '22 at 21:35
-
@VictorChelaru Unity has a Built-in [`UnityEngine.Random.Range(float, float)`](https://docs.unity3d.com/ScriptReference/Random.Range.html) that I would prefer in this case just for the simplicity ;) – derHugo Jan 26 '22 at 08:06
1 Answers
1
What you could use is the built in unity function of Random.Range(minValue, maxValue)
and than where you spawn the prefab you assign a variable using Random.Range
as the x location. Example from Unity Offical API

Enoch
- 11
- 2