- Home /
Player takes damage on collision with an enemy
So i'm working a game where zombies(cubes) follow the player around and do damage when they collide with the player. I can get the enemies to follow the player just fine but i can't manage a code to damage and destroy the zombies(tried with raycast) or that will cause damage to the player when the zombies collide with it. Maybe tags with an OnCollisionEnter might work. Not really sure. I'd really appreciate some help.
I found this and it's exactly what I'm going for : http://www.twiik.net/content/twiikashoot
Answer by Imankit · Mar 08, 2013 at 04:42 AM
Make a public static variable of your health...
example:
Attach this script to your zombies and use this health as your player's health
public static float health = 100;
void OnCollisionEnter(Collision col){
if(col.gameObject.name == "Player"){
health-=5;
}
}
Your answer
Follow this Question
Related Questions
Detecting Raycast collision on an enemy to deal damage 1 Answer
Determining rotation for collision avoidance? 3 Answers
Trouble sending message... 2 Answers
Align to grid in runtime problem 1 Answer
Deal Damage On Collision 3 Answers