Quantcast
Viewing all articles
Browse latest Browse all 1488

Melee Damage script by collision

Hi, I'm working on a 2D game and I have been having some problems with melee damage by collision, I made this script: public class AttackScript : MonoBehaviour { public float damage = 50.0F; public float attackDuration = 0.3F; public bool attacking = false; [HideInInspector] void Start () { } void Update() { if(Input.GetKeyDown("h")){ attacking = true; } } void OnTriggerEnter (Collider col) { if(col.tag == "Enemy") { if(attacking) { col.SendMessage("receiveDamage", damage ,SendMessageOptions.DontRequireReceiver); } } } void EnableDamage() { if (attacking == true) return; attacking = true; StartCoroutine("DisableDamage"); } IEnumerator DisableDamage() { yield return new WaitForSeconds(attackDuration); attacking = false; } } And the enemy's health script: public class EnemyHealth : MonoBehaviour { public float maxHP = 100.0F; public float currentHP; public GameObject Enemy; // Use this for initialization void Start () { currentHP = maxHP; } // Update is called once per frame void Update () { checkStatus(); } public void checkStatus(){ if(currentHP > maxHP) currentHP = maxHP; if(currentHP < 0) currentHP = 0; if(currentHP == 0) death(); } public void receiveDamage(float damage){ currentHP -= damage; Debug.Log("Damage Applied"); } public void death(){ Destroy(this.gameObject); } } ---------------- But for some reason it doesn't work, I tried a lot of things and it doesn't work, some help please?

Viewing all articles
Browse latest Browse all 1488

Trending Articles