- Home /
The question is answered, right answer was accepted
How to randomly generate coins in game during runtime of game?
Hi, I'm new to unity js programming and i'm trying to generate coins randomly during runtime of game.
What part do you have problems with: creating a coin object, instantiating it at runtime, or placing it at a random location? And do you really mean random? Or just one of a set number of possible locations?
Answer by Roobr_Arcade · Oct 14, 2013 at 09:13 PM
//create array of coins, in Unity editor, size the array, drag prefab coins into the array
Public GameObject[] arrayOfCoins;
//get a random coin from the array
GameObject coin = arrayOfCoins[math.Random(0,arrayOfCoins.GetUpperbound(0))];
//instantiate the coin
Instantiate(coin , new Vector3(x, y, z), Quaternion.identity);
(Formatting :P Highlight the code and click the 101010 button above the text box)
Follow this Question
Related Questions
Game Logic - How to Check if player has enough Coins before Instanstiating a House? 1 Answer
How to make A coin shop Button 1 Answer
How can I save the gold in my game scene to the main menu scene? 1 Answer
Accumulate coins using variables (in-app purchases) 1 Answer
How to save coins with PlayerPrefs 2 Answers