0

所以我使用 AttachToController 脚本来附加一个浮动在控制器顶部的窗口——效果很好。在调用窗口的脚本中,我找出了哪只手按下了控制器的菜单按钮并适当地设置了手型字段(左或右)。我要解决的问题是:假设用户单击右侧控制器的菜单按钮,然后单击左侧菜单按钮。我遇到的问题是,即使我更改了惯用手字段,窗口仍然显示为附加到正确的控制器。

private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs args)
{
    hand = args.state.source.handedness;
    ...
}

private void SetHandednessAndActivate(GameObject go)
{
    AttachToController script = go.GetComponentInChildren<AttachToController>();
    if (script != null)
    {
        script.Handedness = hand;           
    }
    go.SetActive(true);
}

需要明确的是,如果用户首先单击左侧控制器菜单按钮,则窗口始终位于左侧,右侧控制器也是如此。我想要的是让窗口移动到使用的任何控制器。

4

1 回答 1

0

代替

script.Handedness = hand;

采用

script.ChangeHandedness(hand);

所有其他位都由脚本处理。

于 2018-08-14T20:56:45.230 回答