- Home /
Make objects randomly fall
I am making a 3D game where objects are supposed to fall randomly everywhere as the player tries to avoid them. There are 4-5 different objects and they all are supposed to disappear after 5 seconds (NOT when they fall off of the screen). I've hear that there is a way to use the random.range function, but am not well educated in that field.
Answer by GanemVisk · Dec 12, 2019 at 08:52 PM
You can destroy a GameObject with Destroy(obj, timeDelay);
where 'obj' is the object to destroy and 'timeDelay' a float.
Random.range(float min, float max)
returns a random float between min and max. You can use that to place your objects at random positions by changing their transform position, for example: obj.transform.position = new Vector3(Random.Range(0, 10), 10, Random.Range(0, 10));
places 'obj' at y = 10 and a random position where x and z are more than 0 and less than 10. You can place this in a component on the objects themselves or on the one that creates them.
Your answer
Follow this Question
Related Questions
Instantiate Random 3D Objects/platforms that dont overlap 1 Answer
How to spawn random buildings 5 Answers
Random target not working 0 Answers
Randomly generating flat landmasses 1 Answer
Falling through platforms 1 Answer