コード例 #1
0
ファイル: PlayerController.cs プロジェクト: Xemar5/Pok
    private void OnTouchHandle(TouchHandler touchHandler)
    {
        OnTryJump?.Invoke(this);
        if (CanMove == false)
        {
            return;
        }
        if (lastInput == touchHandler)
        {
            return;
        }
        if (jumpsLeft == 0)
        {
            bufferedTouch     = touchHandler;
            bufferedTouchTime = Time.time;
            return;
        }
        if (lastJumpTime + minJumpInterval > Time.time)
        {
            bufferedTouch     = touchHandler;
            bufferedTouchTime = Time.time;
            return;
        }
        bool rushing = OnStopRushCharge(touchHandler);

        lastJumpTime = Time.time;
        lastInput    = touchHandler;

        float rushScale = rushing ? rushForceMultiplier : 1;

        Vector2 velocity = new Vector2(
            touchHandler.Direction * sidewardVelocity * timeScaller.TimeScale * rushScale,
            upwardVelocity * timeScaller.TimeScale * rushScale);

        rigidbody2D.velocity = velocity;
        if (jumpsLeft > 0)
        {
            jumpsLeft -= 1;
        }
        playerVisuals.PlayJumpParticles(-velocity.normalized);
        MusicPlayer.Instance.PlayJump();
        OnJump?.Invoke(this);
    }