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

Player wont take damage

$
0
0
Hey so for some reason my player wont take damage when he collides with an enemy can someone help me? the error I get is `NullReferenceException: Object reference not set to an instance of an object StoneGolemController.OnCollisionEnter (UnityEngine.Collision collision) (at Assets/Scripts/Enemies/StoneGolem/StoneGolemController.cs:51) Here is my collide part public void OnCollisionEnter(Collision collision) { if (collision.transform.tag == "Player") { attackDamage = Random.Range(minAttackDamage, maxAttackDamage); critDamage = attackDamage * 3; float randValue = Random.value; if (randValue < critChance) { //Crit attack Debug.Log("Crit attack " + critDamage); PlayerController pHealth = collision.collider.GetComponent(); pHealth.TakeDamagePlayer(critDamage); } else { //Normal attack Debug.Log("Normal attack " + attackDamage); PlayerController pHealth = collision.collider.GetComponent(); pHealth.TakeDamagePlayer(attackDamage); } } } and here is the player takedamage part public void TakeDamagePlayer(int damage) { currentHealth -= damage; healthBar.SetHealth(currentHealth); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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