So I have a for loop that triggers when an enemy dies and rolls a dice to see if it drops certain items. The for loop works fine, but ‘lootBag’ will not instantiate in the scene. There is no errors, and the console can return both the object itself and its value as well as position and none of it is null. What was also strange is when it said that it had spawned but wasn’t in the scene, I checked its transform position, and it was exactly where another version of the prefab existed in the scene, so I thought maybe it was somehow getting refrence from that prefab in the scene or something. But, I deleted the prefab from the scene and the for loop returns its old postion. This probably has nothing to do with it, but I thought it might be relevant. I am very confused, and was wondering if anyone has any ideas?
Code:
public Item[] drops;
public float[] chance;
private float dice;
private GameObject lootBag;
public void dropLoot()
{
for (int i = 0; i < drops.Length; i++)
{
if (drops *!= null) //checks if the item in the array is actually there.*
{
if(chance != 0) //checks if the drop chance is > 0.
{
dice = Random.Range(0, 100); //rolls dice for drop.
if (dice <= chance*) //checks if it landed in the chance range.*
{
lootBag = Resources.Load(“drops/DroppedItem”);
Instantiate(lootBag, transform);
}
} else
{
Debug.Log(drops*.name + “'s drop chance is zero. Why did you do that?”); //prints if the items chance is zero.*
}
}
}
}
}