- Home /
 
Help with player death on collision!
I have been trying to kill my player when he collides with another object in my game, its working but only the first time. When I respawn and walk back to the spikes he just stands on them like they were any other platform. Here is my player script (Written in C#)
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
 [System.Serializable]
 public class PlayerStats {
     public int Health = 3;
 }
 public PlayerStats playerStats = new PlayerStats();
 public int fallBoundary = -20;
 void Update() {
             if (transform.position.y <= fallBoundary)
             DamagePlayer (500);
     }
 public void OnCollisionEnter2D(Collision2D coll)
 {
     if (coll.gameObject.name == "Spikes")
     {
         DamagePlayer (3);
     
     }
 }
 public void DamagePlayer (int damage) {
         playerStats.Health -= damage;
         if (playerStats.Health <= 0) {
         GameMaster.KillPlayer(this);
     }
 }
     }
 
               Any Help would be greatly appreciated :D
@$$anonymous$$arioGraceZ22
Even if the health didn't reset, it should still kill the player. Since the DamagePlayer method checks for the health when it's 0 or less.
Answer by MechanicalGaming · Jan 12, 2015 at 02:47 AM
Try attaching the a new script to the player with this inside it :
 if(playerStats.Health <= 0)
     {
     Destroy(gameObject);
     }
 
              Answer by minetera2 · Aug 04, 2015 at 02:43 PM
you can do also
 if (Health == -1) {                                   //can be Vector3
             transform.localPosition =new Vector2(1f,2f);
         }                                           //the position 
 
              Your answer
 
             Follow this Question
Related Questions
Cant Find Destruction Code? 1 Answer
How to prevent losing multiple lives at zero health? 2 Answers
OnCollisionEnter issues 3 Answers
Trouble sending message... 2 Answers