Getting error on lesson 30 when I try to instantiate prefab

Getting error on lesson 30 when I use Instantiate(ballPrefab);

UnassignedReferenceException: The variable ballPrefab of BallSpawner has not been assigned.
You probably need to assign the ballPrefab variable of the BallSpawner script in the inspector.
UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:202)
BallSpawner.Start () (at Assets/Scripts/BallSpawner.cs:12)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BallSpawner : MonoBehaviour {

public GameObject ballPrefab;

// Use this for initialization
void Start () {
	//print(ballPrefab);
	Instantiate(ballPrefab);
}

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

}

In your script you made the GameObject ballPrefab public so it would show up in the inspector, remember that you’ll need to drag and drop the ball prefab onto your script’s “empty” ballPrefab slot.

Privacy & Terms