【发布时间】:2019-09-24 19:56:38
【问题描述】:
我有大约 10 个按钮,每个按钮都有一个通过脚本添加的唯一值。我想知道使用 MRTK 手与按钮交互时单击了哪个按钮。
我尝试向使用默认 EventSystem 获取当前选定对象的按钮添加一个 updateField 方法。但是,当我调试时,该值为 null。
public void UpdateField()
{
int dayNumb = EventSystem.current.currentSelectedGameObject.GetComponent<DayButton>().CurrentNumber();
}
NullReferenceException:对象引用未设置为 对象 UpdateInputField.UpdateField () (在 资产/脚本/UpdateInputField.cs:35) UnityEngine.Events.InvokableCall.Invoke() (在 C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166) UnityEngine.Events.UnityEvent.Invoke () (在 C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58) Microsoft.MixedReality.Toolkit.UI.InteractableOnPressReceiver.OnUpdate (Microsoft.MixedReality.Toolkit.UI.InteractableStates 状态, Microsoft.MixedReality.Toolkit.UI.Interactable 源)(在 资产/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Events/InteractableOnPressReceiver.cs:71) Microsoft.MixedReality.Toolkit.UI.Interactable.InternalUpdate () (在 资产/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Interactable.cs:525) Microsoft.MixedReality.Toolkit.UI.Interactable.Update () (在 Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Interactable.cs:506)
【问题讨论】:
-
基于documentation,您可以像在默认的uGUI按钮中一样订阅按钮事件。或者使用来自interactable 功能的事件。
标签: unity3d hololens mrtk hololens-emulator