我有大约 10 个按钮,每个按钮都有一个通过脚本添加的唯一值。我想知道使用 MRTK 手与按钮交互时单击了哪个按钮。
我尝试将 updateField 方法添加到使用默认 EventSystem 获取当前选定对象的按钮。但是,当我调试时,该值为空。
public void UpdateField()
{
int dayNumb = EventSystem.current.currentSelectedGameObject.GetComponent<DayButton>().CurrentNumber();
}
NullReferenceException:对象引用未设置为对象的实例 UpdateInputField.UpdateField ()(在 Assets/Scripts/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 源)(在 Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Events/InteractableOnPressReceiver.cs:71)Microsoft.MixedReality .Toolkit.UI.Interactable.InternalUpdate ()(位于 Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Interactable.cs:525)微软。MixedReality.Toolkit.UI.Interactable.Update () (在 Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Interactable.cs:506)