Having game start with number of players selected

I am using Unity 2d and C#

I can’t seem to find a tutorial with how to create the player that is already in my prefab folder onto the level without the character starting there. So with no code, getting to the level will have no players and with the code, getting to the level will have two players.

For example, if you select 2 players, the game will start with 2 players but before the game starts, you pick the game mode. I am thinking of making a separate script for the 2 players button which will load the game mode screen after clicking it.

Will it go in the same place as my load scene code or put it in void start or void update?

What you could do is put on a script that saves the numbers of player and then adds this to start


here is the documentation


there is also this you could do this requires no extra script and might be cleaner for you.

        //set amount of players
        PlayerPrefs.SetInt("amountPlayers", 2);
        //return int in amountPlayers

the 2 could be an int

for example

int amountPlayer;

amountPlayer = 2;


the annoying thing with playerprefs is that it will save it forever
so when you are testing make sure to have something like this ready(and delete it after you are done)

    void Update()
        //if you press delete you delete all the playerprefs
        if (Input.GetKey(KeyCode.Delete))

I made a short imgur tutorial