Exemplo n.º 1
0
    public Collider2D[] PSlashAttack()
    {
        currSlashTrans = slashSideTrans;

        float verticalAxis = Input.GetAxis("Vertical");

        if (verticalAxis != 0)
        {
            if (verticalAxis > 0)
            {
                currSlashTrans = slashUpTrans;
            }
            else if (verticalAxis < 0 && !aEntity.IsGrounded)
            {
                currSlashTrans = slashDownTrans;
            }
        }

        Instantiate(slashParticles, currSlashTrans.position, Quaternion.identity);

        Collider2D[]  targetsHit    = Physics2D.OverlapBoxAll(new Vector2(currSlashTrans.position.x, currSlashTrans.position.y), slashAttackSize, 0f);
        bool          hitAtLeastOne = false;
        HealthControl healthControl = null;

        foreach (Collider2D col in targetsHit)
        {
            if (col.gameObject.CompareTag("Enemy") || col.gameObject.CompareTag("Hazard"))
            {
                healthControl = col.gameObject.GetComponent <HealthControl>();
                if (healthControl != null)
                {
                    Attack slashAttack = new Attack(slashDamage, gameObject, slashKnockback);
                    if (currSlashTrans == slashUpTrans)
                    {
                        slashAttack.knockback.x = 0;
                    }
                    if (currSlashTrans == slashDownTrans)
                    {
                        slashAttack.knockback.x  = 0;
                        slashAttack.knockback.y *= -1;
                    }

                    Debug.Log("Hit");
                    healthControl.DealDamage(slashAttack);
                }

                hitAtLeastOne = true;
                onSlashHit?.Invoke(healthControl);
            }

            healthControl = null;
        }


        if (hitAtLeastOne)
        {
            CameraManager.instance.AddShake(new CameraManager.Shake(1f, 1f, 0.2f));

            if (!noFullRecoil)
            {
                if (!noRecoil)
                {
                    DownRecoil();
                    SideRecoil();
                }
                UpRecoil();
            }
        }

        slashCooldownCounter = slashCooldownDuration;
        CanActivate          = false;

        return(targetsHit);
    }