I have a simple script to keep track of the players health and destruction, but it won’t work fully. The health does work and colliding with objects works fine, but I can’t get it to destroy the object when the player is at 0 health.
using UnityEngine;
using System.Collections;
public class damagePlayer : MonoBehaviour {
public int playerHealth=30;
int damage=10;
void Start()
{
print (playerHealth);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Colliders")
{
playerHealth-=damage;
print ("Player hit" + playerHealth);
}
}
void update()
{
if (playerHealth <= 0)
{
Destroy (this.gameObject);
}
}
}
Thank you very much. I never noticed that error.
– 9182justin