im trying to randomize my loot system, i use 2 random numbers to do this, one for drop chance and one for picking the loot out of a list.
the problem is every time i generate loot its the first on the list.
can someone please show me what im doing wrong?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Loot : MonoBehaviour {
public ItemDatabase itemDatabase;
public List<Item> lootList;
public List<Item> itemDrop;
public Rigidbody2D physicalLootPrefab;
public float lootRNG;
public int pickerRNG;
void Start () {
itemDatabase = gameObject.GetComponent<ItemDatabase>();
}
void Update(){
lootRNG = Random.Range (0.0f, 100.1f);
pickerRNG = Random.Range (0, 22);
}
public void LootTable(Transform enemy, EnemyStats type){
switch (type.enemyType){
case EnemyStats.EnemyType.Lowly:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
if(itemDatabase.items[i].itemRarity == Item.Rarity.Common){
lootList.Add (itemDatabase.items[i]);
}
if(itemDatabase.items[i].itemRarity == Item.Rarity.Uncommon){
lootList.Add (itemDatabase.items[i]);
}
if(itemDatabase.items[i].itemRarity == Item.Rarity.Rare){
lootList.Add (itemDatabase.items[i]);
}
if(itemDatabase.items[i].itemRarity == Item.Rarity.Rarer){
lootList.Add (itemDatabase.items[i]);
}
if(itemDatabase.items[i].itemRarity == Item.Rarity.SaughtAfter){
lootList.Add (itemDatabase.items[i]);
}
if(itemDatabase.items[i].itemRarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
default:{
break;
}
}
}
void LootPicker(Transform enemy){
if (lootRNG >= 50.0f && lootRNG <= 75.0f) {
if(lootList[pickerRNG].itemRarity == Item.Rarity.Common){
itemDrop.Add(lootList[pickerRNG]);
MakeLoot(enemy);
}
}
if(lootRNG > 75.0f && lootRNG <= 87.5f){
if(lootList[pickerRNG].itemRarity == Item.Rarity.Uncommon){
itemDrop.Add(lootList[pickerRNG]);
MakeLoot(enemy);
}
}
if(lootRNG < 93.7f && lootRNG >= 87.5f){
if(lootList[pickerRNG].itemRarity == Item.Rarity.Rare){
itemDrop.Add(lootList[pickerRNG]);
MakeLoot(enemy);
}
}
if(lootRNG < 97.0f && lootRNG >= 93.7f){
if(lootList[pickerRNG].itemRarity == Item.Rarity.Rarer){
itemDrop.Add(lootList[pickerRNG]);
MakeLoot(enemy);
}
}
if(lootRNG < 99.0f && lootRNG >= 97.0f){
if(lootList[pickerRNG].itemRarity == Item.Rarity.SaughtAfter){
itemDrop.Add(lootList[pickerRNG]);
MakeLoot(enemy);
}
}
if(lootRNG >= 99.0f){
if(lootList[pickerRNG].itemRarity == Item.Rarity.Legend){
itemDrop.Add(lootList[pickerRNG]);
MakeLoot(enemy);
}
}
}
void MakeLoot(Transform target){
Vector3 position = new Vector3(target.transform.localPosition.x, target.localPosition.y, 0);
physicalLootPrefab = Instantiate(physicalLootPrefab, position, Quaternion.identity)as Rigidbody2D;
}
}