private void FixedUpdate()
        {
            if (!player.HasTrait(PlayerTraits.Traits.CanWallJump) || player.CheckState(StateLabels.IsInGravityField))
            {
                return;
            }

            if (!canAttachToWall && player.CheckState(StateLabels.IsJumping))
            {
                canAttachToWall = true;
            }
            if (player.CheckState(StateLabels.IsGrounded))
            {
                leftGroundTime = Time.time;
            }

            if (state == States.OnWall)
            {
                if (Time.time > wallAttachTime + WallAttachDuration || !player.CheckState(StateLabels.IsAgainstWall))
                {
                    player.GetPlayerState().Set(StateLabels.IsAttachedToWall, false);
                    state           = States.None;
                    canAttachToWall = false;

                    if (!player.CheckState(StateLabels.IsJumping))
                    {
                        gravity.ApplyNormalGravity();
                    }
                }
            }

            if (state == States.None && !player.CheckState(StateLabels.IsGrounded))
            {
                if (canAttachToWall && player.CheckState(StateLabels.IsAgainstWall) && !player.CheckState(StateLabels.IsStomping) &&
                    Mathf.Abs(playerController.GetMoveDirection().x) > 0.1f && Time.time > leftGroundTime + AttachFromGroundDelay)
                {
                    state         = States.OnWall;
                    wallDirection = player.IsFacingRight() ? 1 : -1;
                    player.GetPlayerState().Set(StateLabels.IsAttachedToWall, true);
                    wallAttachTime = Time.time;

                    RaycastHit2D hit = Physics2D.Raycast(player.transform.position, Vector2.right * wallDirection, 3f, 1 << LayerMask.NameToLayer("Terrain"));
                    if (hit.collider != null)
                    {
                        attachEffect.transform.position = hit.point;
                    }
                    attachEffect.Play();
                }
            }
        }
Exemplo n.º 2
0
        private void Update()
        {
            switch (state)
            {
            case States.Inactive:
                break;

            case States.Active:
                crosshair.Move(controller.GetMoveDirection(), MaxDistance);
                break;

            case States.Blinking:
                blinkTime     += Time.deltaTime;
                Time.timeScale = Mathf.Lerp(TimeScale, 1, blinkTime / BlinkDuration);
                if (blinkTime > BlinkDuration)
                {
                    Stop();
                }
                break;

            default:
                break;
            }
        }