I am a complete noob when it comes to coding in unity . I have a couple of different enemies that are scriptable objects and when I start a battle I would like to load a random one of those enemies. Can anyone please help I cant figure out how to do it.
Asked
Active
Viewed 162 times
1
-
You could load the objects into an array then just pull a random index. – Aggressor Jul 24 '22 at 13:24
-
Please provide enough code so others can better understand or reproduce the problem. – Community Jul 25 '22 at 01:43
1 Answers
0
It depends on what you have. Are you loading Scriptable Objects from the Resources folder? If you are, you may use Object[] enemies = Resources.LoadAll("Enemies", typeof(Enemy))
. This code will load everything of a type "Enemy" from a folder "Resources/Enemies/". Then you can get random numbers from 0 to enemies.Length and get an object from the array using the number as an index

Dasic
- 29
- 5