Item Drop From List Of Six Possible Items Question. C#

Hello :slight_smile:

I’ve been pouring over the docs and googling for about two hours now and still can’t figure this one out.

Basically I have a crate, I have it to where it can be destroyed and then it drops an item. Now I can’t seem to figure out the best method of randomizing the drop. I was reading over Random.Range in the Unity Docs and am curious if this would be a good way to randomly instantiate an item from a list. Also what would be the best method of creating said list. I have a personal preference of using…

public GameObject[] Items;

So I can just visually drag and drop the prefabs for the items into the slots but am open to other ways of doing it.

If my option is viable could I get Random.Range to select one of the prefabs in the list then instantiate it on the crates demise?

Thank you for the help

New to scripting yes, I’ve been working with a couple different projects with other groups of people doing just modeling and level design which is why I am more comfortable with visual application rather than hard coding it all. Basically I’m just trying to grasp scripting so I can start doing some small projects on my own for learning reasons and just having fun :smiley:

So here is my current idea as far as the scripting goes for the random drop out of the crate using my GameObject array and the Random.Range

using UnityEngine;
using System.Collections;

public class CrateScript : MonoBehaviour {

	public GameObject[] Items;
	public int CrateHealth = 10;

	// Use this for initialization
	void Start () {
	
	}

	void ApplyDamage (int TheDamage) 
	{
		CrateHealth -= TheDamage;
	}
	
	// Update is called once per frame
	void Update ()
		{
			if(CrateHealth <= 0)
			{
				Death();
			}
		}

	void Death()
	{
		Destroy(gameObject);
		Instantiate(Items[Random.Range(0, Items.Length)], transform.position, Quaternion.identity);
	}
}

But for some reason no items are spawning /: