I’m having a strange problem with my script and can’t figure out why. When I click a button it drops the appropriate object but always remove the highest up button from the GUI. Any possible solutions would be awesome, tia!
for(int i = 0; i < inventory.Count; i++) {
if(GUILayout.Button(inventory[i].item_name)) {
DropItem(inventory[i]);
}
}
public bool DropItem(Item newItem) {
GameObject player = GameObject.Find ("Player");
GameObject instance = (GameObject)Instantiate(Resources.Load(newItem.item_name), player.transform.position + player.transform.forward + Vector3.up* 0.5f, player.transform.rotation);
instance.name = newItem.item_name;
inventory.Remove(newItem);
return true;
}