Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (hitFrame > 0)
        {
            hitFrame -= 1;
            if (hitFrame <= 0)
            {
                animCtrl.RemoveLayer(2);
            }
        }

        if (isClimbing)
        {
            Collider2D climbingColliderBelow = GetClimbingColliderBelow();
            Collider2D climbingColliderAbove = GetClimbingColliderAbove();

            if (isOnGround || (climbingColliderBelow == null && climbingColliderAbove == null))
            {
                FinishClimb(false);
            }
        }
        else
        {
            //if (Input.GetKeyDown(KeyCode.P))
            //{
            //    KnockBack();
            //}

            //if (isKnockingBack)
            //{
            //    rb2d.velocity = new Vector2(-15f, rb2d.velocity.y);
            //    KnockingBackFrame -= 1;
            //    if (KnockingBackFrame <= 0)
            //    {
            //        isKnockingBack = false;
            //    }
            //}



            //if (controller.Roll && AllowRoll())
            //{
            //    if (controller.DLateral > 0.5f)
            //    {
            //        isRolling = true;
            //        RollingLastFrame = 6;
            //        LockedSpd = Vector2.right * RollSpd;
            //        animCtrl.SetTrigger("Roll");
            //    }
            //    else if (controller.DLateral < -0.5f)
            //    {
            //        RollingLastFrame = 6;
            //        isRolling = true;
            //        LockedSpd = Vector2.left * RollSpd;
            //        animCtrl.SetTrigger("Roll");
            //    }
            //}

            //if (isRolling)
            //{
            //    rb2d.velocity = LockedSpd;
            //    RollingLastFrame -= 1;
            //    if (RollingLastFrame <= 0)
            //    {
            //        animCtrl.SetTrigger("Ground");
            //        isRolling = false;
            //    }
            //}


            //核心判断


            //判断是否在空中
            if (isJump)
            {
                if (!isFalling && rb2d.velocity.y <= 0)
                {
                    isFalling = true;
                    animCtrl.SetTrigger("Fall");
                }
            }
            if (isFalling)
            {
                if (isGroundedNew)
                {
                    isJump    = false;
                    isFalling = false;
                    animCtrl.SetTrigger("Ground");
                }
            }


            if (!isJump && !isFalling && !isGroundedNew)
            {
                isFalling = true;
                animCtrl.SetTrigger("Fall");
            }

            isOnGround = isGroundedNew && !isJump && !isFalling;


            Vector2 extraV = Vector2.zero;
            if (mFootDetector.HoldBelow != null && (mFootDetector.HoldBelow as MovingPlatform) != null)
            {
                //extraV = (mFootDetector.HoldBelow as MovingPlatform).NowVVector;
            }

            float vx = 1 * BaseMoveSpd;
            TurnDirection(vx);
            //斜坡过大 可能还会有傻逼问题
            if (isOnGround && Mathf.Abs(vx) < 0.5f)
            {
                LockPosition(true);
            }
            else
            {
                LockPosition(false);
            }

            //if (isOnGround)
            //{
            //    GroundedVerticalMovement();
            //}
            //else
            //{
            //    AirborneVerticalMovement();
            //}



            if (isJump || Mathf.Abs(vx) < 1f)
            {
                animCtrl.LogicAnimator.SetFloat("GroundSpeed", Mathf.Abs(vx));
                animCtrl.ViewAnimator.SetFloat("GroundSpeed", Mathf.Abs(vx));
            }
            else
            {
                animCtrl.LogicAnimator.SetFloat("GroundSpeed", Mathf.Abs(vx));
                animCtrl.ViewAnimator.SetFloat("GroundSpeed", Mathf.Abs(vx));
            }

            if (AllowMove())
            {
                //NextMovement += Vector2.right * vx * Time.deltaTime;
                rb2d.velocity = new Vector2(vx, rb2d.velocity.y);
                //SetHorizontalMovement(vx);
                //Vector3 move = Vector2.right * vx * Time.deltaTime;
                //transform.position += move;
            }

            if (isAttacking())
            {
                if (isJump)
                {
                    rb2d.velocity = new Vector2(vx, rb2d.velocity.y);
                }
                else
                {
                    rb2d.velocity = new Vector2(0, rb2d.velocity.y);
                }
            }

            if (AllowUseSkill())
            {
                mActCtrl.CheckInput();
            }

            if (isOnGround)
            {
                rb2d.position += extraV * Time.deltaTime;
            }
        }
    }