- Home /
Clicker game instantiate prefab depending on gold per click
Hello, I'm trying to make a clicker game replica of "Get A Little Gold" (you can find it on Kongregate) and I'm currently trying to find a solution to instantiate a gold chip prefab every time i click, but it needs to depend on my gold per click . I have built a custom class for the gold chips and every gold chip that I instantiate carries it, and it stores the gold chip value. here is how i want the logic to be like - for example: if I have 5 gold per click - when i click i want it to instantiate 1 gold chip with a value of 5. and if for example i have 23 gold per click, i want it to instantiate 2 gold chips with a value of 10, and 3 with a value of 1. this is how I tried doing it so far, Im using an array of the gold chips, and it doesnt really work out for me. Here is the code:
public void Click(){
float moneyToCover = Stats.goldPerClick;
for (int i = 0; i < shards.Length; i++) {
for (int y = 0; y < moneyToCover; y++) {
if (moneyToCover % shards [i].value <= 0) {
Instantiate (shards [i].gameObject, GenerateRandomPosition (), Quaternion.identity, canvas.transform);
moneyToCover -= shards [i].value;
}
}
}
}