Skip to content
Snippets Groups Projects
PlayerHealth.cs 735 B
using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {

    /*SCRIPT FOR WHEN THE ENEMY IS HIT, NOT THE PLAYER*/
    void Start() {
        GameObject weapon = GameObject.Find("weapon");
        Physics2D.IgnoreCollision(weapon.GetComponent<Collider2D>(), GetComponent<Collider2D>());
    }
    //apply damage if the collision is the enemy
    void OnCollisionEnter2D(Collision2D other) {
        if (other.gameObject.name == "Enemy") {
            Debug.Log("Enemy hit");
            other.gameObject.SendMessage("ApplyDamageE", 1, SendMessageOptions.DontRequireReceiver);
            other.gameObject.SendMessage("ChangeHealthBare", 1, SendMessageOptions.DontRequireReceiver);
        }
    }

}