Instantiate Prefab problem

I have a little problem with instantiate ı have a code as that ;

var prefab : GameObject ;


function Update () {
	if (Input.GetMouseButton(0)) {
		var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		var hit: RaycastHit;
		
		if (Physics.Raycast(ray, hit)) {
			Instantiate(prefab, hit.point, Quaternion.identity);
		} 
	}
}

I have a Cube as prefab. When i play and clicked to any area i take this error.

NullReferenceException: The prefab you want to instantiate is null. UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) NewBehaviourScript 1.Update () (at Assets\NewBehaviourScript 1.js:12)

How can i insert my prefab in my scene where my clicked ?

Can you help me ?[ ]

Did you AT LEAST set something in the Inspector, in the spawning script ?

Hello Akilae

How is spawning script ?

Regards

First, rename that script before you get crazy, I don’t even understand why you left the default name. You want to get lost or…?

Second, you put that script on a game object, right ?

Look at that gameObject in the inspector, and look at that script. Did you put something (the gameobject to instantiate) in the right box ?

The spawning script should show “Prefab” option in the Inspector. Drag your prefab asset to this.

Otherwise script has no idea what to Instantiate.

For sanity reasons, wise to check references like these aren’t Null.

Thank you! You are great!

Problem is solved![/list]