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

How to make my player not lose health when attacking the enemy?

$
0
0
I feel like this is basic problem but I have set up and enemy (sawblade) that upon colliding with the player will take away 10 health points. However, my player has a slide animation that i am using as a way to attack the sawblade and destroy it. The player slides and hits the enemy destroying it but my problem is that upon doing this the player itself loses health. Below I will place my script from the Sawblade script that I have which indicates that when the player collides with the sawblade the player gets ten points taken away (Take Damage(10)). I thought that if I just did an else statement the sawblade would cancel damage taken when the player collides while sliding but that is not the case, what can i do to fix this? void OnTriggerEnter(Collider c) { if(c.tag=="Player"){ GameObject healthGameObject=GameObject.Find("Health"); healthGameObject.GetComponent().TakeDamage(10); }else{ if (GameObject.Find("Player").GetComponent().sliding){ GameObject healthGameObject=GameObject.Find("Health"); healthGameObject.GetComponent().TakeDamage(0); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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