List / Array Extra Help!

I’ve watched every single tutorial on lists, seen how to add different values to them, etc. But none on how to actually use them.

Let’s say I made a list of Weapons and they had varying differences in damage.

List<Weapons> weapons = new List<Weapons>();

weapons.Add( new Weapons("Sword", 50));
weapons.Add( new Weapons("Knife", 20));
weapons.Add( new Weapons("Gun", 100));

If I wanted to make a GUI made of buttons, clicking the button would equip the weapon by instantiating it and changing it’s transform, and then when you use it, it inflicts the int of damage to any enemy. If I already know how to do make and use the weapon, how do I implement a list for use?

Or let’s say I have a list of colors of enemies and their probabilities of being spawned.

List<Rabbits> rabbit = new List<Rabbits>();

rabbit.Add( new Rabbits("Blue",0.60));
rabbit.Add ( new Rabbits("Red",0.20));
rabbit.Add ( new Rabbits("Silver",0.19));
rabbit.Add ( new Rabbits("Gold",0.01));

How would this be attached to a spawner that makes instantiations and how are these probabilities determined from the list?

Examples that you have all used for your games would be also very very appreciated!
Thank you.

have you used arrays before? they’re the same, to get a list item you just do something like myList [indexYouWant].

so to instantiate something you’d do (pseudo) Instantiate (gunsList [indexToSpawn].gameObject, position, rotation);

1 Like