Skip to content
Snippets Groups Projects
EnemyHealth.cs 741 B
using UnityEngine;
using System.Collections;

public class EnemyHealth : MonoBehaviour {

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

}