- Home /
Tanks Tutorial - Set Number of Players
Assuming there are 4 tanks placed in the Tanks tutorial scene, how can you toggle between 1 to 4 players with an options button? Would the buttons enable and disable the tanks based on number of players selected? Or can you change the arrays length to limit the maximum number of tanks that spawn? Or maybe the button would just set a public integer value and say for (int i = 0; i < [integer value specified by button]; i++)?
Answer by gvergidis · Sep 19, 2018 at 10:23 AM
Hello. Try making your code a bit more dynamic. In cases like your, avoid using Arrays and use Lists. So for example we should have that kind of code :
List<TanksObject> listOfTanks = new List<TanksObject>();
So when you want to add a tank in the list you would do :
listOfTanks.add(aNewTank);
and you would do a loop like this :
foreach(TanksObject tank in listOfTanks)
{
// Loops through all tanks added in the list
}
Lowering the players count would be easy. All you have to do is :
listOfTanks.remove(tankToRemove);
I hope this helps. If you still have problems, please post a snippet of code so we can further help you.
Thank you, this helped push me in the right direction. I will give this a shot shortly.
Thank you, @gvergidis. I was able to achieve the game mechanics I wanted by using Lists with your guidance.
Your answer

Follow this Question
Related Questions
How to setup a lan system 1 Answer
UNET Players are movable on collision 2 Answers
Recognize number of players and set differents input for an action 0 Answers
Unity networking tutorial? 6 Answers