Пример #1
0
    protected override void Update()
    {
        base.Update();

        if (attackCooldown > 0)
        {
            attackCooldown -= Time.deltaTime;
        }
        if (iFrames > 0)
        {
            iFrames -= Time.deltaTime;
        }
        //Set airTime based on If touching Floor
        if (!touchingFloor)
        {
            airTime += 1 * Time.deltaTime;
        }
        else
        {
            airTime = 0;
        }
        //Set wallJumpTime based of If touching Wall
        if (!touchingRight && !touchingLeft || touchingFloor)
        {
            wallJumpTime += 1 * Time.deltaTime;
        }
        else
        {
            wallJumpTime = 0;
        }

        //Animations for touching walls
        if (rb.velocity.y <= -2)
        {
            if (facingRight)
            {
                animator.SetBool("SlidingRightWall", touchingRight);
                if (!touchingRight)
                {
                    animator.SetBool("SlidingLeftWall", touchingLeft);
                }
                else
                {
                    animator.SetBool("SlidingLeftWall", false);
                }
            }
            else
            {
                animator.SetBool("SlidingRightWall", touchingLeft);
                if (!touchingRight)
                {
                    animator.SetBool("SlidingLeftWall", touchingRight);
                }
                else
                {
                    animator.SetBool("SlidingLeftWall", false);
                }
            }
        }
        else
        {
            animator.SetBool("SlidingRightWall", false);
            animator.SetBool("SlidingLeftWall", false);
        }

        if (inpJumpTime < 1)
        {
            inpJumpTime += Time.deltaTime;
        }
        if (inpAttackTime < 1)
        {
            inpAttackTime += Time.deltaTime;
        }

        //Trigger Attack
        if (attackCooldown <= 0 && inpAttackTime < 0.1)
        {
            if (weaponBehavior)
            {
                weaponBehavior.StartCoroutine("Attack");
                inpAttackTime  = 1;
                attackCooldown = weaponBehavior.WeaponItem.cooldown;
            }
        }
    }