Hello again I'm doing the racing game and am trying to do on my map to pick up items but I want mariokart style that I picked up a box and inside it was the system of random selection I've ever even imagine how I can do that, I'm wanting to do an arraylist and my items will be on them and send randonizar this list to get a random value, could someone help me please. Thanks I await answers. Obs:I am using C#. Thanks.
Something like this will work for you. Code (csharp): Random random = new Random(); var myItem = myItemArray[random.Next(myItemArray.Length)]; When you need a percentage chance for every item, there are different approaches. For example: http://www.vcskicks.com/random-element.php
Thanks Marrrk. Now enjoy it as I could make the system of positions, for example display on my screen that I'm in first, second or third place could help me please? Thanks.
Marrrk. Desculpe mas o seu código não funcionou e eu precisava dele em C# se poder coloca variavel para mim tambem pois não estou sabendo como declarar em C# uma array ja olhei na documentação da unity mas lá só mostro como é a declaração em javascript poderia por favor me ajudar?
To your last post (I hope i did understand it, I dont speak any portuguese): You dont need an array if you want to dynamically add items into the list of available items (also its eadier to explain everything with a list). Declare and define a List of Items; Code (csharp): List<UsableItem> myItems = new List<UsableItem>(); myItems.Add(new HomingMissile()); myItems.Add(new Missile()); myItems.Add(new Shield()); myItems.Add(new Booster()); myItems.Add(new SuperBoost()); If you want this as an Array: Code (csharp): UsableItem[] myItems = UsableItem[] { new HomingMissile(), new Missile(), new Shield(), new Booster(), new SuperBoost() }; Alternative: Code (csharp): UsableItem[] myItems = UsableItem[5]; myItems[0] = new HomingMissile(); myItems[1] = new Missile(); myItems[2] = new Shield(); myItems[3] = new Booster(); myItems[4] = new SuperBoost(); Everything else in my code should be usable as it is. To your first post: I would nsuggest that you look into the GUI classes and simply display a texture with the position of the player according to the current placing of the player. Please elaborate your problem.
Sorry Marrrk, I am Brazilian and I ended up writing in Portuguese my problem that was up there but what I was trying to say is that I needed the example in C # and was not finding a good example in the documentation of unity, but had imagined that to was equal to an ArrayList as it is in java. But thanks! =)