- Home /
Lower Object Health If Collides With "Player" Tag,Lower Object Health If Collides With Player Tag
I have an object that basically chases the player. It has a starting health of "5". When its health reaches zero the object explodes (destroying the object). How can I make the health of the object go straight to zero when it collides with anything tagged "Player"? I would appreciate any help, because this is one of the last touches to my newest game. For whatever reason, I cannot get it to work. If you need more information, then I can supply the health script. It is all written in C#. Thanks ahead of time for your help.
Answer by ahaykal · May 30, 2013 at 08:05 AM
void OnCollisionEnter (Collision other)
{
if(other.gameObject.tag == "Player")
{
health = 0;
}
}
For the record, I doubt that these are your last touches, because if you still don't know how to do that, its highly unlikely that you would be able to do a game.
Anyway good luck in your game and try to see other user's questions/answers, I am pretty sure a lot asked that from before.
It is the last touches. The game has a couple of game modes One of them had to be written primarily in C#, and my native language is Javascript. I know very little about C#. This is the last game mode left to make, and all the others were written in javascript. A friend helped out and wrote the script for this object, but it is in C#, so I needed help making changes to it. Anyways, thanks for your help. I will try this.
Your answer
Follow this Question
Related Questions
Play annimation on collision not working. 1 Answer
how do i make an Enemy take damage from prefab bullet clone? 1 Answer
kill boundary script 1 Answer
Enemy not taking damage on collisions. 2 Answers