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 RealMTG · May 10, 2014 at 09:16 PM · arrayselection

Array Selection(?)

Hi!

I got a pretty complex thing to ask. I do not know if the title is fitting but here is my question.

I'm making a small game like this one: http://www.kongregate.com/games/stripedypaper/tf2-crate-sim

It is a Team Fortress 2 Crate Simulator. If you aren't familiar with Team Fortress 2 crates, here is a explanation. If you are, go a head and skip this chunk of text. The Team Fortress 2 crates is basically crates that you can open. You can get a key and open them. The crates can contain hats, weapons, "unusual" hats e.t.c. Some random stuff. Weapons have like 70% of uncrating. Hats have about 25%. Unusual hats have like 5%. These numbers aren't 100% correct because it honestly don't know.

Now, my question is, how do I get specific items to get selected from a array of items when I click my button? I need a name, icon and a value to appear on the screen. I have made this kind of "array in array" style when I make the items. See bottom of page for example on array in array. I also need the chance of the item to spawn. If I set Item 1's chance to 80 and Item 2's chance to 10, Item 1 will appear more frequent then Item 2 will.

If you know what to do, please tell me! And please tell me any code in C#.

Thanks

Array in array example:

alt text

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by haim96 · May 10, 2014 at 09:26 PM

i think you need to create a class for your item. this class will hold the item name, item prefab or icon name if it's not like item name and some other properties you want.

here tutorial how to create these: http://unity3d.com/learn/tutorials/modules/intermediate/scripting/properties

then you need to create an array from the class you created. this might help you with this: http://answers.unity3d.com/questions/684845/array-of-custom-properties-c.html

finally, you can create a button that when you press it it will pick a random number. this number will be index from that array. then you can use the data from the selected array variable to display on the screen.

hope it give you some direction...

Comment
Add comment · Show 3 · 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 haim96 · May 10, 2014 at 09:40 PM 0
Share

to be more specific:

you create class called ITE$$anonymous$$S:

 public class items
 {
   public int power{ get; set;}}
   public string Name{ get; set;}
   public gameobject GO{ get; set;}
 }

then create an array of it:

 private items[] ItemsData = new items[3];

and initialized it:

 for (int i = 0; i < ItemsData.Length; ++i) {
   ItemsData[i] = new items();
 }


then random a number:

  int number= random.range(0,ItemsData.Length-1);


then use the properties like this

 itemsData[nember].go = somePrefabName

 
avatar image RealMTG · May 10, 2014 at 10:06 PM 0
Share

I appreciate your help but I don't understand this. At all. Is there any other way?

avatar image haim96 · May 11, 2014 at 07:10 AM 0
Share

what part you don't understand?

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

21 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

Related Questions

[SOLVED]Object selection scrip doesn't work. 2 Answers

Weapon selection system 2 Answers

"add selected" editor script 1 Answer

Argument is out of range in array 1 Answer

audio array touch selection 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