我正在尝试运行该函数的脚本如下所示:
public class switchAnimation : MonoBehaviour {
public GameObject Character;
private Animator myController;
void Awake()
{
myController = Character.GetComponent<Animator>();
}
public void playPositive_large()
{
myController.SetTrigger("P_l");
}
}
我正试图从另一个脚本运行它:
68: switchAnimation SA = GetComponent<switchAnimation>();
69: SA.playPositive_large();
但它给了我以下错误:
“NullReferenceException:对象引用未设置为对象的实例 Buttons.myAnims(UnityEngine.EventSystems.BaseEventData baseEvent)(在Assets / Main_A1 / Buttons.cs:69) UnityEngine.Events.InvokableCall
1[UnityEngine.EventSystems.BaseEventData].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:189) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773) UnityEngine.Events.UnityEvent
1 [T0] .Invoke(.T0 arg0)(在C:/buildslave/unity/build/Runtime/Export/UnityEvent_1.cs:53) UnityEngine.EventSystems.EventTrigger.Execute(EventTriggerType id,UnityEngine.EventSystems.BaseEventData eventData)(at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/EventTrigger.cs:67) UnityEngine.EventSystems.EventTrigger.OnPointerEnter(UnityEngine.EventSystems.PointerEventData eventData)(在C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/EventTrigger.cs:73) UnityEngine.EventSystems.ExecuteEvents.Execute(IPointerEnterHandler handler,UnityEngine.EventSystems.BaseEventData eventData)(在C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:22) UnityEngine.EventSystems.ExecuteEvents.Execute [IPointerEnterHandler](UnityEngine.GameObject target,UnityEngine.EventSystems.BaseEventData eventData,UnityEngine.EventSystems.EventFunction`1 functor)(位于C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI /EventSystem/ExecuteEvents.cs:261) UnityEngine.EventSystems.EventSystem:更新() “
我尝试了不同的方法来调用函数,但或多或少我得到了相同的错误!