Example #1
0
    public void Attack()
    {
        timer -= Time.deltaTime;

        vampire.Anim.SetBool("attacking", (timer <0.5 || timer> 1.5) && countOfStrikes > 0);

        if (countOfStrikes > 0 && timer <= 0)
        {
            for (int i = 0; i < 3; i++)
            {
                GameObject fireBallClone = GameObject.Instantiate(vampire.fireBall, vampire.transform.position, Quaternion.identity);
                float      directionX    = Mathf.Sign(vampire.Player.transform.position.x - vampire.transform.position.x);
                Vector2    speed         = new Vector2(directionX * Mathf.Cos(i * Mathf.PI / 8), Mathf.Sin(i * Mathf.PI / 8)) * speedOfFireBall;
                fireBallClone.GetComponent <Rigidbody2D>().velocity = speed;
                timer = attackCd;
            }
            countOfStrikes--;
        }
        else if (countOfStrikes == 0 && timer <= 0)
        {
            vampire.Anim.SetBool("humanForm", false);
            vampire.Anim.SetBool("beastForm", true);
        }

        if (vampire.transform.position.x < vampire.Player.transform.position.x && vampire.FacingRight)
        {
            vampire.Flip();
        }
        else if (vampire.transform.position.x > vampire.Player.transform.position.x && !vampire.FacingRight)
        {
            vampire.Flip();
        }
    }
Example #2
0
    public void Attack()
    {
        grounded = Physics2D.OverlapCircle(vampire.groundCheck.position, groundRadius, vampire.whatIsGround);
        vampire.Anim.SetBool("grounded", grounded);

        jumpTimer -= Time.deltaTime;

        if (!vampire.Stunned)
        {
            if (grounded)
            {
                jump = false;
                vampire.Anim.SetBool("prepare", jumpTimer < 0.5f && jumpTimer > 0 && countOfJumps > 0);

                if (!jump && jumpTimer <= 0)
                {
                    if (countOfJumps > 0)
                    {
                        jump          = true;
                        vampire.Speed = (vampire.Player.transform.position.x - vampire.Rb.position.x) * 2 / 3;
                        vampire.Rb.AddForce(new Vector2(0, jumpForce));
                        jumpTimer = jumpCd;
                        countOfJumps--;
                    }
                    else
                    {
                        vampire.Anim.SetBool("beastForm", false);
                        vampire.Anim.SetBool("humanForm", true);
                    }
                }
            }
            else
            {
                vampire.Rb.velocity = new Vector2(vampire.Speed, vampire.Rb.velocity.y);
            }
        }

        if (grounded)
        {
            vampire.Rb.velocity = new Vector2(-vampire.Rb.velocity.x, vampire.Rb.velocity.y);

            if (vampire.transform.position.x < vampire.Player.transform.position.x && vampire.FacingRight)
            {
                vampire.Flip();
            }
            else if (vampire.transform.position.x > vampire.Player.transform.position.x && !vampire.FacingRight)
            {
                vampire.Flip();
            }
        }
    }