- Home /
Player spawning systems.
Hello, I'm currently working a robot game based off the cartoon network.com game, Dexter's Bot Brigade.
So for my game, the player would place down a robot of one of three types, sort of a rock-paper-scissors system.
What I'm wondering, is how can I create a script that spawns a random one of these types for the player to use and?
I have already set the movement for one of the objects. So how might I create a spawning system for the player to get one of the robots?
Answer by JasonBennett · Feb 14, 2020 at 07:59 PM
Hello @Bluesharky38,
I'm happy to explain this more in depth if you need it, but roughly you just need to do the following:
public List<GameObject> robots;
Start()
{
}
public GameObject ChooseRobot()
{
int randomNumber = Random(0, robots.Count - 1);
return robots[randomNumber];
}
Then go into the inspector and set your list size and assign the robot prefabs to the slot. You can call this ChooseRobot() method any time you want a random robot. You might need to cast the Random() as an int, in which case it would be
(int)Random(0, robots.Count - 1);
Let me know if that helps or if you need further explanation.
-Jason
Okay, I think I understand.
So would I need to put this in the script for each of the robots or would I put this in like a game manager script?
Sorry, I still fairly new to unity.
Thank you again for your time :)
Your answer
Follow this Question
Related Questions
Tank not moving towards player 1 Answer
Ragdoll toggle unity 2d 1 Answer
player rule builder 2 Answers
Enemies spawning on player and rotated 1 Answer
¿Los controles del Player se programan diferente para cada plataforma? 0 Answers