Exemplo n.º 1
0
    public void DamageUnit(int damage)
    {
        int damageTaken;

        damageTaken = CalculateDamage(damage);
        _isKilled   = _myHealth.ChangeHealth(-damageTaken);
        if (_isKilled)
        {
            if (SoundController._instance._soundOn)
            {
                _myAudioSource.PlayOneShot(_myDeathClip);
            }
            if (!_isDesignerMode)
            {
                _myAnimator.SetTrigger("Die");
            }
            else
            {
                DeathEnded();
            }
        }
        else
        {
            if (SoundController._instance._soundOn)
            {
                _myAudioSource.PlayOneShot(_myDamageClip);
            }
            if (!_isDesignerMode)
            {
                _myAnimator.SetTrigger("TakeDamage");
            }
        }
    }
Exemplo n.º 2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            HealthController playerHpCon = other.gameObject.GetComponent <HealthController>();
            if (playerHpCon != null && playerHpCon.timer <= 0)
            {
                playerHpCon.ChangeHealth(dmg);

                if (knockback > 0)
                {
                    Rigidbody2D player = other.gameObject.GetComponent <Rigidbody2D>();
                    player.velocity = (player.transform.position - gameObject.transform.position) * (knockback + Random.Range(-knockbackRandomness, knockbackRandomness));
                }
                if (stunLock > 0)
                {
                    PlayerController pc = other.gameObject.GetComponent <PlayerController>();
                    if (pc != null)
                    {
                        pc.stunTimer = stunLock;
                    }
                }

                Debug.Log("Player Hit");
                cam.Shake(0.1f, 0.2f);

                if (destroyAfter)
                {
                    DestroyObject();
                }
            }
        }
    }
Exemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        //the Enemys Rigidbodys sleeping mode must be set to never sleep for collisions to take place when the object is stoped...

        //theres got be be a better way to do this...
        if (other.tag == "Player" || other.name.Contains("CameraZone") == true || other.tag == "Npc")
        {
            return;
        }
        cam.Shake(0.1f, 0.2f);
        HealthController     hpController = other.GetComponent <HealthController>();
        AnimatorStateInfo    stateInfo    = playerAnimator.GetCurrentAnimatorStateInfo(0);
        Rigidbody2D          rb           = other.GetComponent <Rigidbody2D>();
        EnemyMovementManager emm          = other.GetComponent <EnemyMovementManager>();

        if (stateInfo.fullPathHash == attackHash)
        {
            print(name + " hit " + other.name);

            if (hpController != null && hpController.timer <= 0)
            {
                hpController.ChangeHealth(damage);
                cam.Shake(0.1f, 0.2f);

                if (rb != null)
                {
                    rb.velocity = (rb.transform.position - player.transform.position) * knockback;
                }
                if (emm != null)
                {
                    emm.stunTimer = stun;
                }
            }
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Enemy")
        {
            HealthController enemyHpCon = other.gameObject.GetComponent <HealthController>();
            if (enemyHpCon != null && enemyHpCon.timer <= 0)
            {
                enemyHpCon.ChangeHealth(dmg);

                if (knockback > 0)
                {
                    Rigidbody2D enemy = other.gameObject.GetComponent <Rigidbody2D>();
                    enemy.velocity = (enemy.transform.position - gameObject.transform.position) * (knockback + Random.Range(-knockbackRandomness, knockbackRandomness));
                }
                if (stunLock > 0)
                {
                    EnemyMovementManager ec = other.gameObject.GetComponent <EnemyMovementManager>();
                    if (ec != null)
                    {
                        ec.stunTimer = stunLock;
                    }
                }

                Debug.Log("Enemy Hit");

                if (destroyAfter)
                {
                    DestroyObject();
                }
            }
        }
    }
Exemplo n.º 5
0
    IEnumerator DealDamage()
    {
        while (true)
        {
            yield return(new WaitForSeconds(DamageDelay));

            hc.ChangeHealth(-Mathf.Abs(Damage));
        }
    }
Exemplo n.º 6
0
        bool IDamageReceiver.ApplyDamage(IDamageProvider damageProvider)
        {
            if (!enabled)
            {
                return(false);
            }

            var healthDiff = _healthController.ChangeHealth(-damageProvider.DamageValue);

            return(healthDiff != 0);
        }
Exemplo n.º 7
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (!_hasLeftOrigin && collision.gameObject == Origin)
         return;
     if (collision.gameObject.CompareTag("Sword"))
         return;
     HealthController otherHealthController = collision.gameObject.GetComponent<HealthController>();
     if (otherHealthController == null || otherHealthController.IsIntangible)
         return;
     otherHealthController?.ChangeHealth(-_damage);
     Destroy(gameObject);
     Hit?.Invoke();
 }
Exemplo n.º 8
0
    /// <summary>
    /// OnTriggerEnter is called when the Collider other enters the trigger.
    /// </summary>
    /// <param name="other">The other Collider involved in this collision.</param>
    void OnTriggerEnter(Collider other)
    {
        if (!other.GetComponent <HealthController>())
        {
            return;
        }
        if (IgnoredTags.Any(other.tag.Contains))
        {
            return;
        }

        print($"Dealing damage to {other.name}");
        HealthController health = other.GetComponent <HealthController>();

        health.ChangeHealth(-Damage);
    }
Exemplo n.º 9
0
    private void Hit(GameObject target)
    {
        HealthController healthController = target.GetComponent <HealthController>();

        healthController?.ChangeHealth(-_damage);
    }