Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SuperCrow2 · Nov 23, 2018 at 05:18 PM · instantiateprefabgameprogramminglevel

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aardappel156 · Nov 23, 2018 at 10:27 PM 0
Share

I might not really understand your question. So you want the user first choose how many player are going to play. Then choose a gamemode and after that the game start with the gamemode and amount of players

like this Choose player screen > choose gamemode > level start with amount of player from the choose players screen

avatar image SuperCrow2 aardappel156 · Nov 23, 2018 at 11:21 PM 0
Share

Yes that is right.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aardappel156 · Nov 23, 2018 at 11:26 PM

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

 DontDestroyOnLoad(this.gameObject);

here is the documentation

edit:

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
         PlayerPrefs.GetInt("amountPlayers");

the 2 could be an int

for example

 int amountPlayer;
 
 amountPlayer = 2;
 
 PlayerPrefs.SetInt("amountPlayers",amountPlayer);
 

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))
         {
             PlayerPrefs.DeleteAll();
         }
     }


https://imgur.com/a/hPbguj4

^^ I made a short imgur tutorial

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SuperCrow2 · Nov 23, 2018 at 11:47 PM 0
Share

Thanks I will try the second one.

Should I make a new script for it and just add that script where it needs to be added or load up the "number of players" or "game mode" script and add it there?

And yeah, I noticed that in play mode, unity saves all the information until you exit play mode and go back in it so I had to reset everything via code.

avatar image aardappel156 SuperCrow2 · Nov 23, 2018 at 11:52 PM 0
Share

I would recommend the script where the player chooses the number of players. so when the player chooses the number also put that value and set the playerpref.

avatar image SuperCrow2 aardappel156 · Nov 23, 2018 at 11:55 PM 0
Share

When you say "playerpref" thats what I named it in my prefs folder right? so I would replace "playerpref" with the name I gave it?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How to randomly instantiate other prefabs parallel? 1 Answer

Scrolling level Instantiate after cycle 0 Answers

Optimisation for 3D level creation 0 Answers

How to generate different diagonal platforms? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges