Unity 3D试图禁用操纵杆控制,以便角色可以在瞄准时移动

发布于 2025-01-30 19:41:01 字数 1536 浏览 4 评论 0原文

我正在尝试禁用操纵杆控件,因此当我缩小角色(并且他的瞄准)时,如果玩家在瞄准模式时遇到了操纵杆,他就不会开始移动。

我正在使用启动器资产的 - 新输入系统(动作类型/PassThrough&passhrough& control type/vector2) - 我使用的是运动混合树(2D自由形式的方向作为混合类型)

(两个)下面的行是我要禁用的)

playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue<Vector2>();    
        playerControls.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();


    private void OnEnable()
    {
        if (playerControls == null)
        {
            playerControls = new PlayerControls();

            playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue<Vector2>();    
            playerControls.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();

            playerControls.PlayerMovement.Run.performed += i => runInput = true; /// Hold
            playerControls.PlayerMovement.Run.canceled += i => runInput = false; /// Let Go

            playerControls.PlayerMovement.QuickTurn.performed += i => QuickTurnInput = true;

            playerControls.PlayerActions.Aim.performed += i => aimingInput= true; 
            playerControls.PlayerActions.Aim.canceled += i => aimingInput = false;

            playerControls.PlayerActions.Shoot.performed += i => shootInput = true;
            playerControls.PlayerActions.Shoot.canceled += i => shootInput = false;
        }

        playerControls.Enable();
    }

I'm trying to disable the joystick controls so when I zoom in on my character(and he is aiming), he won't start to move if the player accidently hits the joystick while he is in aim mode.

I'm using the --new input system from the starter assets (action type/passthrough & control type/Vector2)-- and I'm using a locomotion blend tree (2D free form Directional as the blend type)

(The two lines below are what I want to disable)

playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue<Vector2>();    
        playerControls.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();


    private void OnEnable()
    {
        if (playerControls == null)
        {
            playerControls = new PlayerControls();

            playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue<Vector2>();    
            playerControls.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();

            playerControls.PlayerMovement.Run.performed += i => runInput = true; /// Hold
            playerControls.PlayerMovement.Run.canceled += i => runInput = false; /// Let Go

            playerControls.PlayerMovement.QuickTurn.performed += i => QuickTurnInput = true;

            playerControls.PlayerActions.Aim.performed += i => aimingInput= true; 
            playerControls.PlayerActions.Aim.canceled += i => aimingInput = false;

            playerControls.PlayerActions.Shoot.performed += i => shootInput = true;
            playerControls.PlayerActions.Shoot.canceled += i => shootInput = false;
        }

        playerControls.Enable();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

刘备忘录 2025-02-06 19:41:01

我最好的选择是让您在AIM进行这样的操作时禁用运动:

playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue() && playerControler.PlayerActions.Aim.performed;
playerControls.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue() && playerControler.PlayerActions.Aim.performed;

您可以尝试一下,但将此摘要移到目标下方。

My best bet is for you to disable movement while aim was performed like this:

playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue() && playerControler.PlayerActions.Aim.performed;
playerControls.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue() && playerControler.PlayerActions.Aim.performed;

You can try it, but move this snippet below your Aim.performed snippet

花心好男孩 2025-02-06 19:41:01

我在大多数情况下都想出了它。 不幸的是,这是我使用的

    if (playerManager.isAiming)
        {
            playerControls.PlayerMovement.Movement.performed += i => movementInput = Vector2.zero;
        }
        else
        {
            playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue<Vector2>();
        }

布尔值,我忘了禁用,这就是给我大部分问题的原因。

I figured it out for the most part. here is what I used

    if (playerManager.isAiming)
        {
            playerControls.PlayerMovement.Movement.performed += i => movementInput = Vector2.zero;
        }
        else
        {
            playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue<Vector2>();
        }

unfortunately I had a boolean that I forgot to disable so that is what gave me most of my problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文