Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 dany88 · Jul 17, 2013 at 01:47 PM · randomspawningarraylist

Create a function that spawn player (wich datas are stored in an array) randomly

I'm trying to make a function that spawn player stored in an array randomly but I'm having this problem": i don't know how to take each value ( for ex. each firstname, lastname) of each user. The array is like this:

[{"firstname":"daniele","lastname":"daveri","username":"dany","gender":"male"},{"firstname":"admin","lastname":"admin","username":"admin","gender":"male"},{"firstname":"prova3","lastname":"prova3","username":"prova3","gender":"male"},{"firstname":"pp","lastname":"pp","username":"pp","gender":"male"}]

So for example for the player : "daniele" the system spawn a male player prefab and so for all player stored in the array.

Thanks!

Comment
Add comment · Show 3
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 dorpeleg · Jul 17, 2013 at 01:56 PM 0
Share

This site is not meant for "make the code for me" questions.

This site is meant for questions like "I'm trying to make a function that spawn player stored in an array randomly but I'm having this problem"

Please update your question with your problem or learn to code.

avatar image Yokimato · Jul 17, 2013 at 02:33 PM 0
Share

@dorpeleg, I didn't take his question as "write this for me", though it was a bit vague. Giving him a starting point is certainly a do-able thing. The comment about "learn to code" is exactly what we don't need here.

avatar image dany88 · Jul 17, 2013 at 04:26 PM 0
Share

exactly...

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Yokimato · Jul 17, 2013 at 01:57 PM

You can do random spawning many ways however having learned my lesson from doing it all programmatically, I'd suggest doing it only partially.

In your scene you could make a game object for each valid spawn location and tag it as "spawnLocation". Then using GameObject.FindGameObjectsWithTag("spawnLocation") you can an array of valid locations. Grab a random index from this array and use the object's transform.position.

This allows for more control of what's a valid location and avoids issues where the player could spawn in the terrain for instance.

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 gamesbyangelina · Jul 17, 2013 at 03:08 PM

If you're using the first name to look up the rest of the information, you might like to use a Map. Maps are data structures that associate one piece of data (called a Key) with another (called a Value). So you would have a map like this:

 PlayerData daniele = PlayerDataMap.get("Daniele");
 //More code here

I know this isn't a complete answer for you but hopefully it might help! Here's some info on Dictionaries in C#, which have this feature: http://www.dotnetperls.com/dictionary

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 dany88 · Jul 17, 2013 at 03:05 PM

ok thanks ! however i don't know how to take each values for each player in the array. thanks!

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 inkspot · Jul 17, 2013 at 03:16 PM

You can do this by inserting an array into an array, here's a small example of how the idea works (if i understood you correctly);

 var mainarray : new Array();
 
 mainarray.Add("firstname","daniele","lastname","daveri","username","dany","gender","male");
 
 var playertospawn = mainarray[0]; /// gets first entry of the mainarray //
 
 var playername = playertospawn[1]; /// gets 2th entry which is daniele //




Comment
Add comment · Show 2 · 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 dany88 · Jul 17, 2013 at 04:22 PM 0
Share

thanks so much! I need to put in the array the values automatically, but i dnt know how to automatically select for ex the value :"daniele" from the complete string..

re thanks!! :)

avatar image inkspot · Jul 18, 2013 at 12:57 AM 0
Share

Your welcome i hope it solved your problem

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

19 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

Related Questions

i want to spawn randomly 1 Answer

script not working pls solve it 1 Answer

How can I create a script to create and then randomly select 1 of 3 spawning points? 1 Answer

How to generate random objects? 1 Answer

Instantiate random object from Array 2 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