在 Update() 之外从 C# 脚本更改滑块的值?

问题描述

由于某种原因,我得到了 nullReferenceException,但在尝试更改 slider.value 的同时,某些代码在 Update() 中运行良好!

所以我创建了一个由一些脚本引用的函数来尝试更改滑块值但总是得到错误

NullReferenceException: Object reference not set to an instance of an object
UIModController.ChangeSliderValue (system.int32 value) (at Assets/scripts/UIModController.cs:145)
ToggleSwitch.Switch () (at Assets/scripts/ToggleSwitch.cs:165)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:66)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:108)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler,UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target,UnityEngine.EventSystems.BaseEventData eventData,UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/EventSystem.cs:377)

出于某种原因,行 SliderController.value = value; 仅适用于 Update() ,这对我不起作用!这是我想从中更改滑块值的函数

public void ChangeSliderValue(int value)
{
    SliderController.value = value;
}

任何帮助将不胜感激:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)