OnCollisionStay2D()

private void OnCollisionStay2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            //  Debug.Log("OnCollisionStay "+isPlaying(animator, "hero_attack_persistant"));
            if (swordAttacking)
            { //|| isPlaying(animator, "hero_attack_persistant") == true
              //kill enemy if attack animation is playing when colliding
              //Destroy(other.gameObject);
                animator.SetBool("whenHit", false);
            }
            else
            {
                bool disFroze = false;
                if (other.gameObject.TryGetComponent(out HealthAndDeath had))
                {
                    if (had.isFrozen)
                    {
                        disFroze = true;
                    }
                }
                if (!disFroze)
                {
                    animator.SetBool("whenHit", true);
                    Debug.Log(other.gameObject.tag + " is tag.");
                    if (other.gameObject.TryGetComponent(out IDamageable hds) && !other.gameObject.CompareTag("HeroWeapon"))
                    {
                        hds.ReceiveDamage(hds.SendDamage());
                    }
                }
                //hero dead
                //clearActions();
                //Destroy(gameObject);
            }
        }
        if (other.gameObject.CompareTag("Boss"))
        {
            if (boss.GetComponent().attacking == true)
            {
                Boss struckBoss = boss.GetComponent();
                struckBoss.HitReceived(inventory.usingThis);
                animator.SetBool("whenHit", true);
                Debug.Log("Boss hit w/: " + inventory.usingThis.GetName());
            }
        }
        if (isOnBranchSide() && other.gameObject.CompareTag("Branch"))
        {
            //  shouldCrawl = true;
            isJumping = false;
            if (!crawlMade)
            {
                crawlToHere = new Vector2(other.transform.position.x + polygonCollider2D.bounds.size[0], other.transform.position.y + polygonCollider2D.bounds.size[1]);
                crawlMade = true;
            }
        }
    }


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *