Question by
importguru88 · Aug 21, 2016 at 10:50 PM ·
variableassignunassignedreferenceexcept
UnassignedReferenceException: The variable enemy of EnemiesSpawner has not been assigned
The enemies are spawning fine . I keep getting this error when I play the 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. Here is my script:
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