Quantcast
Channel: Answers by "IvovdMarel"
Viewing all articles
Browse latest Browse all 145

Answer by IvovdMarel

$
0
0
I'm assuming the object with the tag "Enemy" have a component EnemyHealth. If that's the case, you want to access that particular enemy and it's component. Rather than calling enemyHealth (which is a private property in your bullet-script, but has never been assigned, which causes the null reference), you should write void OnCollisionEnter(Collision col) { if (col.gameObject.tag == "Enemy") { col.GetComponent().curHealth -= 10; } } Or, if you want to get rid of the tag completely: void OnCollisionEnter(Collision col) { EnemyHealth enemy = col.GetComponent(); if (enemy != null) { enemy.curHealth -= 10; } }

Viewing all articles
Browse latest Browse all 145

Trending Articles



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