How to CREATE A RANDOM OBJECT by code in Unity

Опубликовано: 06 Март 2025
на канале: GDT Solutions
371
9

In this video we see how to create a random object selected from a list of GameObjects in Unity.
The key is how you get the reference of the GameObject you want to create, once you do it you simply create a GameObject with the Instantiate function using that reference.

This is the previous video where we saw how to create PREFABS AT RUNTIME in Unity:
   • How to CREATE OBJECT by code in Unity  

The select a random object from a list of GameObjects we use the Random.Range function passing 0 and the size of the array as parameters, then use that random value to access to an element of the list of objects and that's the reference you use to create the random object.

____________________________________________________________
PORTFOLIO: https://gamedevtraum.com/en/portfolio...
CONTACT:   / gamedevtraum  
LINKEDIN:   / gamedevtraum  
____________________________________________________________