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 AXORTH · Mar 20, 2019 at 02:09 PM · gameobjectnetworkrandom

HOW TO CHOOSE ONE OF THE PLAYERS AND TRANSFORM IT IN A PREFAB?

Hi ! I am a beginner on Unity and I have a problem... I am currently creating a game that uses UNet and, once the number of players connected in a room, starts a game. During the game there will be one of the 10 players who will be chosen randomly and will become a hunter. The others will have to go hide themselves.

So I don't know how to make sure that one of the players is chosen at random and turns into a different prefab when starting the game.

I do not know where to start so any help would be welcome !!

PS: Excuse me if there are misspellings I am French and I'm not strong at english

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by dargonknight · Mar 20, 2019 at 02:17 PM

@AXORTH there are a number of ways to deal with the this for beginners I would suggest that you pick a player at random from the server and activate a bool "IsHunter" (it could even be an other script or child gameobject) while turning off the initial settings of the "hunted" this would make it possible for you to make 1 prefab that contains all of your settings instead of trying to change the spawn etc... (even though your request is possible this is the easiest approach u can have).

SMALL FRENCH EXPLANATION:

il te faudrai un avoir les 2 object dans le meme prefab player et puis tu active le Hunter pour le joueur que tu choisi et tu desactive l autre du coups sa te simplifira le travail enorement.

Comment
Add comment · 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
0

Answer by AXORTH · Mar 20, 2019 at 02:29 PM

Thank you @dargonknight for making a French translation! Thanks to you I understood how to do Did you know how to select at random one of all connected players ? Thank you !

Comment
Add comment · Show 4 · 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 dargonknight · Mar 20, 2019 at 03:25 PM 0
Share

@AXORTH pour la prochaine fois utilise "Add Comment" pour faire un commentaire et ne pas ajouter une reponse. as for the random selection on the server you can go as simply as getting the list of the connected players and using the function Random.Range of unity.

 public void selectRandomPlayer(List <Player> players)
 {
 //random index 
 int index = Random.Range.(0, players.Count); 
 //function where you turn ur player to a hunter but dont forget to use the proper networking functions this script is solely a selection script (preferably used on the server and RPCing the answer to other players etc...)
 players[index].setHunter();
 }


French explanation: le bute ici est de simplement faire une liste de tes joueur et utiliser la fonction proposer de unity pour avoir un index aux hasard que tu utilisera pour faire ton choix

avatar image AXORTH · Mar 20, 2019 at 05:11 PM 0
Share

@dargonknight Thanks for all ! The only problem is when I type the code, the word "Player" is wrong... Yet my player is named Player Photo here.

avatar image dargonknight AXORTH · Mar 20, 2019 at 10:15 PM 0
Share

@AXORTH my code was an example the Player is the class i m using you should use your own class

avatar image AXORTH dargonknight · Mar 21, 2019 at 01:14 PM 0
Share

thx @dargonknight

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

181 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I want gameobjects to move randomly on screen without overlapping.` 2 Answers

How to randomly spawn three non repeating gameobjects from an array? 2 Answers

Spawn random amount apart of each other 1 Answer

Randomly generating Character Controllers? 0 Answers

Missiles don't go for random targets... 1 Answer


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