Prefab clone not working

Hi everyone,

Im very new to unity and I am trying to create 5 of the same game object using a prefab but for some reason it does not work. (Unity - Manual: Instantiating Prefabs at run time iv been using this)

I have done all of the instructions (create cube, add rigidbody and drag it into the prefab) and the code in the script is as followed

using UnityEngine;
using System.Collections;

public class multiboxes : MonoBehaviour {

	public Rigidbody boxR;

	// Use this for initialization
	void Start () 
	{
		for (int i = 0; i < 5; i++) 
		{
			Vector3 position = new Vector3 (Random.Range (-3.0f, 3.0f), Random.Range (-2.0f, 2.0f), -2.0f);
			Rigidbody boxclone = (Rigidbody)Instantiate (boxR, position, Quaternion.identity);
		}
	}

	// Update is called once per frame
	void Update () 
	{
	

	}
}

I have also made sure that I dragged the prefab into the BoxR rigidbody.

[34725-prefab+data.png|34725]

Any help will be very appreciated.

Here, try this code:
using UnityEngine;
using System.Collections;

public class multiboxes : MonoBehaviour {

	public GameObject boxR;
	
	// Use this for initialization
	void Start () 
	{
		for (int i = 0; i < 5; i++) 
		{
			Vector3 position = new Vector3 (Random.Range (-3.0f, 3.0f), Random.Range (-2.0f, 2.0f), -2.0f);
			GameObject boxclone = (GameObject)Instantiate (boxR, position, Quaternion.identity);
		}
	}
	
	// Update is called once per frame
	void Update () 
	{
		
		
	}
}

The reason it wasn’t working is that you were trying to instantiate Rigidbodies, which are just components. To actually create an object, you would have to instantiate a GameObject. I hope this helps.