- Home /
Question by
importguru88 · Aug 21, 2016 at 10:54 PM ·
variableassignunassignedreferenceexcept
UnassignedReferenceException: The variable enemy of EnemiesSpawner has not been assigned unity3d
I am getting this error every time when I play my scene :
UnassignedReferenceException: The variable enemy of EnemiesSpawner has not been assigned. You probably need to assign the enemy variable of the EnemiesSpawner script in the inspector.
using UnityEngine;
using System.Collections;
public class EnemiesSpawner : MonoBehaviour {
public GameObject enemy;
public Transform [] spawnPoints;
public float spawnTime = 5f;
public Vector3 spawnValues;
void Start () {
InvokeRepeating("Spawn", spawnTime, spawnTime); //Calls the "Spawn" function every 10 seconds.
}
void Spawn () {
int spawnPointIndex = Random.Range (0, spawnPoints.Length); for( int spawnCount = spawnPoints.Length - 1 ; spawnCount >= 0 ; --spawnCount )
Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, -spawnValues.z) ) ; // <= here
}
}
Comment
UnassignedReferenceException: The variable enemy of EnemiesSpawner has not been assigned. You probably need to assign the enemy variable of the EnemiesSpawner script in the inspector. This doesn't help?
Did you drag and drop the "enemy" gameobject into the public space provided in the inspector ?? You have to do that..