Spawning Random Objects?

My game object is a crate. I also have another object. When I keep going, I want either one of those objects to spawn in a specific location. How can I implement something like through coding?

I’d do:

public class ClassName : MonoBehaviour {
     [SerializeField]  private ObjectInfo[] objects;  // fill in editor
     GameObject GetRandomObject(ObjectInfo[] objects){
          float chance = Random.Range(0,100); // random (0 to 99) %
          foreach (ObjectInfo obj in objects) {
             // Check if random is in chance
             if (chance < obj.chance) {
                 return obj.obj; // returns object
             // Fix chance for next item
             chance -= (int)item.chance;

 public struct ObjectInfo{ // structure for object information
          public GameObject obj; // Prefab
          public short chance; // (0 to 99) %

this is an great method for readable code and to have a nice structure in your editor.

Put your objects in an array, get a random index for that array and instantiate that object:

public GameObject[] myObjects;

int randomIndex = Random.Range(0, myObjects.Length);

GameObject instantiatedObject = Instantiate(myObjects[randomIndex], position, Quaternion.identity) as GameObject;

When you instantiate random objects it is possible that two same objects instantiate.
So , Take a list of random numbers and choose one number and remove that number from list , when your list become empty then refill it using recurrsion.
List randomNumber = new List ();

int RandomNumberChooser ()
	if (randomNumber.Count == 0) {
		Fill_List ();
		RandomNumberChooser ();
	var index = Random.Range (0, randomNumber.Count);
	var value = randomNumber [index];
	randomNumber.RemoveAt (index);
	return value;

void Fill_List ()
	for (int i = 0; i < targetArrays.Count; i++) {
		randomNumber.Add (i);


Instantiate your objec at return value from RandomChooser Method
Like this
SelectedRandomNumber = RandomNumberChooser ();
GameObject instantiatedObject = Instantiate(myObjects[SelectedRandomNumber ], position, Quaternion.identity) as GameObject;