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 ![]()