Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

NullReferenceException: Object reference not set to an instance of an object

$
0
0
I have 2 different scripts. 1 of them has int variable count and the other one goes and changes it's value. But I get this error. Can you check it? First Script: using UnityEngine; using System.Collections; public class Spawn : MonoBehaviour { public GameObject monsterPrefab; // Set this in inspector to the monster prefab. public float Delay; public int count; public float canSpawn; void Update() { if (Time.time >= canSpawn) { if (count < 3) { Instantiate(monsterPrefab, transform.position, transform.rotation); count++; canSpawn += Delay + Time.time; } } } } Second Script: using UnityEngine; using System.Collections; public class Health : MonoBehaviour { public float health; Spawn script; private bool _damagedealth = false; private GameObject target; void Start() { health = 100; target = GameObject.FindGameObjectWithTag("Player"); script = GetComponent(); } void Update () { if (health <= 0) { Destroy(this.gameObject); script.count -= 1; } }

Viewing all articles
Browse latest Browse all 171066


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