Exemple #1
0
    public IEnumerator Slash()
    {
        AudioManager.Play("Slashy_hit");
        this.state = SlashyStates.Hit;

        this.Animator.SetTrigger("attack");

        yield return(new WaitForSeconds(0.5f));

        Vector2 center = this.Transform.position;
        var     offset = new Vector2(this.SlashHitBoxOffset.x * this.CharacterController.Direction, this.SlashHitBoxOffset.y);

        center += offset;

        Collider2D[] collided = Physics2D.OverlapAreaAll(center - this.SlashHitboxSize / 2, center + this.SlashHitboxSize / 2);
        Debug.DrawLine(center - this.SlashHitboxSize / 2, center + this.SlashHitboxSize / 2, Color.green);
        foreach (Collider2D collider in collided)
        {
            IHitable target = collider.gameObject.GetComponent <IHitable>();
            if (collider.gameObject != this.gameObject && target != null)
            {
                target.TakeDamages(this.SlashDamages, this.Transform.position);
            }
        }

        yield return(new WaitForSeconds(0.5f));

        this.state = SlashyStates.Follow;
    }
Exemple #2
0
        public IEnumerator Launch()
        {
            if (!_canAttackMele)
            {
                yield break;
            }

            // initialisation
            this._isMeleAttacking        = true;
            this.PlayerStats.IsInvicible = true;

            // animate
            this.Animator.SetBool("PlayerMele", true);

            // activation
            this.Rigidbody.velocity = Vector2.right * this.PushForce * this.CharacterController.Direction;
            yield return(new WaitForSeconds(this.MeleTimeBeforeHit));

            Vector2 center = this.Transform.position;
            var     offset = new Vector2(this.MeleHitBoxOffset.x * this.CharacterController.Direction, this.MeleHitBoxOffset.y);

            center += offset;

            Collider2D[] collided = Physics2D.OverlapAreaAll(center - this.MeleHitboxSize / 2, center + this.MeleHitboxSize / 2);
            foreach (Collider2D collider in collided)
            {
                IHitable target = collider.gameObject.GetComponent <IHitable>();
                if (collider.gameObject != this.gameObject && target != null)
                {
                    target.TakeDamages(this.MeleDamages, this.Transform.position);
                }
            }

            yield return(new WaitForSeconds(this.MeleTimeBetweenHits));

            center   = this.Transform.position;
            collided = Physics2D.OverlapAreaAll(center - this.MeleHitboxSize / 2, center + this.MeleHitboxSize / 2);
            foreach (Collider2D collider in collided)
            {
                IHitable target = collider.gameObject.GetComponent <IHitable>();
                if (collider.gameObject != this.gameObject && target != null)
                {
                    target.TakeDamages(this.MeleDamages, this.Transform.position);
                }
            }

            this._isMeleAttacking = false;

            this.Animator.SetBool("PlayerMele", false);
            this.PlayerStats.IsInvicible = false;

            // cooldown
            this._meleCooldown = true;
            yield return(new WaitForSeconds(this.MeleAttackCoolDown));

            this._meleCooldown = false;
        }
Exemple #3
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        IHitable toKill = collision.gameObject.GetComponent <IHitable>();

        if (toKill != null)
        {
            if (this.ToKillTag == "all")
            {
                toKill.TakeDamages(99999, collision.gameObject.GetComponent <Transform>().position);
            }
            else
            {
                if (this.ToKillTag == collision.gameObject.tag)
                {
                    toKill.TakeDamages(99999, collision.gameObject.GetComponent <Transform>().position);
                }
            }
        }
    }
Exemple #4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        IHitable target = collision.gameObject.GetComponent <IHitable>();

        if (collision.gameObject != From && collision.gameObject.layer != 11)
        {
            if (target != null)
            {
                target.TakeDamages(this.damages, this.Transform.position);
            }
            Destroy(gameObject);
        }
    }