Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

NullRefrenceExeption

$
0
0
Hey guys. I found this script in a older tutorial from 2015 and I cannot fix it. It gives me "NullReferenceExeption: Object reference not set to an instance of an object Spawner.OnEnable () (at Assets/Scripts/Spawner.cs:14) " and "NullReferenceExeption: Object reference not set to an instance of an object Spawner.OnDisable () (at Assets/Scripts/Spawner.cs:14 at the beginning and end of the consol. { public GameObject objectToSpawn; public int numberOfEnemies; private float spawnRadius = 30; private Vector3 spawnPosition; private GameManager_EventMaster eventMasterScript; void OnEnable() { SetInitialReferences(); eventMasterScript.myGeneralEvent += SpawnObject; } void OnDisable() { eventMasterScript.myGeneralEvent -= SpawnObject; } void SpawnObject() { for (int i = 0; i < numberOfEnemies; i++) { spawnPosition = transform.position + Random.insideUnitSphere * spawnRadius; Instantiate (objectToSpawn,spawnPosition,Quaternion.identity); } } void SetInitialReferences() { eventMasterScript = GameObject.Find ("GameManager").GetComponent(); } } And the GameManager_EventMaster: { public delegate void GeneralEvent (); public event GeneralEvent myGeneralEvent; public void CallMyGeneralEvent() { if (myGeneralEvent != null) { myGeneralEvent (); } } } Tutorial: https://www.youtube.com/watch?v=e3OimELNyMc∈dex=12&list=PLwyZdDTyvucwjwqucleVQB7U12H2JPvg5 Add comment

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>