I want to drop items with a rarity factor but only one at a time.
I have this at the moment:
int rarity = Random.Range (0, 101);
for(int i = 0; i < theCurrency.Length;i++ )
if( rarity >= theCurrency*.DropRarity)*
The problem is, if rarity is 0 for example, all items get dropped, instead of just the lowest which has a rarity of 5.
How can i fix it?
Right after your instantiate add the following.
Basically you are looping through all the items and seeing if they are bigger than zero, if they are spawn them. So once you find an item that satisfies the conditions you need to stop looping. Break stops your for loop.
This seems to be a valid solution
int itemWeight = 0;
for(int i = 0; i< theCurrency.Length;i++)
itemWeight += theCurrency*.DropRarity;*
_ if(randomValue <= theCurrency*.DropRarity)_
randomValue -= theCurrency.DropRarity;