- Home /
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:
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...
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
I appreciate your help but I don't understand this. At all. Is there any other way?
Your answer

Follow this Question
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