修改这段代码,让玩家只有在按住按钮时才会移动 UNITY 3D

问题描述 投票:0回答:0

按下一次移动按钮时,角色继续移动而不停止,除非按下另一个按钮 我想修改这段代码,让玩家只有在按下按钮时才会移动

public void Move(Vector3 velocity, bool standingOnPlatform)
    {
        Move(velocity, Vector2.zero, standingOnPlatform);
    }

    public void Move(Vector3 velocity, Vector2 input, bool standingOnPlatform = false, bool isPlayer = false)
    {

        UpdateRaycastOrigins();
        isBelowOld = collisions.below;

        collisions.Reset();
        collisions.velocityOld = velocity;
        playerInput = input;

        if (velocity.x != 0)
        {
            collisions.faceDir = (int)Mathf.Sign(velocity.x);
        }

        if (velocity.y < 0)
        {
            DescendSlope(ref velocity);
        }

        if (HandlePhysic)
        {
            HorizontalCollisions(ref velocity);
            if (velocity.y != 0)
            {
                VerticalCollisions(ref velocity);
            }
        }

        if (collisions.left || collisions.right)
            velocity.x = 0;

        transform.Translate(velocity, Space.World);

        if (standingOnPlatform)
        {
            collisions.below = true;
        }
    }

修改这段代码,让玩家只有在按下按钮时才会移动

unity3d 2d
© www.soinside.com 2019 - 2024. All rights reserved.