Beispiel #1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Sword"))
        {
            //other.GetComponent<Collider>().enabled = false;

            zombieHealthController.ApplyDamage(damage);
            audioSource.PlayOneShot(hitSound, 0.2f);

            //Vector3 awayFromSwordHitPoint = (transform.position - other.gameObject.transform.position);
            Vector3 awayFromPlayer = (transform.position - other.GetComponentInParent <Transform>().position);
            enemyRb.AddForce(awayFromPlayer * 1000f * Time.deltaTime, ForceMode.Impulse);

            Instantiate(bloodEffect, transform.position + new Vector3(0, 1.7f, 0), Quaternion.identity);


            if (zombieHealth > damage)
            {
                actions.Damaged();
            }
            if (zombieHealth <= damage)
            {
                currentState = States.Dead;
            }
            StartCoroutine(CalmDown());
        }
        if (other.CompareTag("Arrow"))
        {
            damage = GameObject.FindWithTag("Arrow").GetComponent <Weapon>().weaponDamage;
            zombieHealthController.ApplyDamage(damage);
            audioSource.PlayOneShot(hitSound, 0.2f);
            Vector3 awayFromPlayer = (transform.position - other.GetComponentInParent <Transform>().position);
            enemyRb.AddForce(awayFromPlayer * 1000f * Time.deltaTime, ForceMode.Impulse);

            Instantiate(bloodEffect, transform.position + new Vector3(0, 1.7f, 0), Quaternion.identity);
            if (zombieHealth > damage)
            {
                actions.Damaged();
            }
            if (zombieHealth <= damage)
            {
                currentState = States.Dead;
            }
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Untagged" || other.gameObject.tag == toDamage)
        {
            if (other.gameObject.tag == toDamage)
            {
                HealthController hp = other.gameObject.GetComponent <HealthController>();
                hp.ApplyDamage(damage);
            }
//            GameObject explosion = Instantiate(bulletExplosionPrefab);
//            explosion.transform.position = transform.position;
            Destroy(this.gameObject);
            GameObject obj = Instantiate(this.createOnBDestroy);
            obj.transform.position = this.transform.position;
        }
    }
 public void ApplyDamage(int amount) => health.ApplyDamage(amount);