using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class character_killer : MonoBehaviour {

    public float health;
    public GameObject blod;

    // Use this for initialization
    void Start() {

    }

    // Update is called once per frame
    void Update() {

    }

    private void OnCollisionEnter(Collision collision) {
        GetDamage(collision.relativeVelocity.magnitude);

    }

    public void GetDamage(float dmg) {
        ComboCenter.Instance.IncreaseScoreBy(1);
        health -= dmg;
        if (health > 0) {
            BroadcastMessage("TakeDamage", dmg, SendMessageOptions.DontRequireReceiver);
        }
        else {
            ComboCenter.Instance.IncreaseScoreBy(10);
            ComboCenter.Instance.IncreaseComboLevel(0.3f);
            BroadcastMessage("Die", dmg, SendMessageOptions.DontRequireReceiver);
            GameObject.Instantiate(blod).transform.position = transform.position+ transform.up*2;
            // disable active colliders
            Collider[] colliders = GetComponentsInChildren<Collider>();
            for (int i = 0; i < colliders.Length; i++) {
                colliders[i].enabled = false;
            }

        }
    }
}