an error pops up when executing the animation code

Viewed 27

Hello there is a problem when using

myAnims.Play (anim1);

Help please - this is the code:

{
    Animator myAnim;
    public string anim1;
    public string anim2;
    public string anim3;
    public string anim4;
    public string anim5;
    public string anim6;
    public bool firstAnimInclouded = true;
    public int rg;
    //public AudioClip saundAnim1;
    //public AudioClip saundAnim2;

    void Start()
    {
        myAnim = GetComponent <Animator> ();
    }

    void Tap()
    {
        if (firstAnimInclouded == true)
        {
            rg = Random.Range(1, 3);
            if (rg == 1)
            {
                myAnim.Play(anim1);
            }
            else
            {
                myAnim.Play(anim2);
            }
        }
    }
}

I get this error:

Animator.GotoState: State could not be found

0x00007ff760ac930d (Unity) StackWalker::GetCurrentCallstack
0x00007ff760acffe9 (Unity) StackWalker::ShowCallstack
0x00007ff761a3d613 (Unity) GetStacktrace
0x00007ff7620d223d (Unity) DebugStringToFile
0x00007ff760e063f7 (Unity) AnimatorControllerPlayable::ValidateGoToState 0x00007ff760e00f7d (Unity) AnimatorControllerPlayable::GotoStateInternal 0x00007ff760e00f16 (Unity) AnimatorControllerPlayable::GotoState 0x00007ff760da5a0d (Unity) Animator::GotoState 0x00007ff75fd8db69 (Unity) Animator_CUSTOM_Play 0x0000024dccfe11c4 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Animator:Play (UnityEngine.Animator,int,int,single) 0x0000024dccfe0f3b (Mono JIT Code) UnityEngine.Animator:Play (string,int,single) 0x0000024dccfe0e8b (Mono JIT Code) UnityEngine.Animator:Play (string) 0x0000024dccfe0beb (Mono JIT Code) [game.cs:38] game:Tap () 0x0000024cfbba9879 (Mono JIT Code) UnityEngine.Events.InvokableCall:Invoke () 0x0000024cfbba926b (Mono JIT Code) UnityEngine.Events.UnityEvent:Invoke () 0x0000024dccfdfba3 (Mono JIT Code) [Button.cs:71] UnityEngine.UI.Button:Press () 0x0000024dccfdfae3 (Mono JIT Code) [Button.cs:115] UnityEngine.UI.Button:OnPointerClick (UnityEngine.EventSystems.PointerEventData) 0x0000024dccfdfa89 (Mono JIT Code) [ExecuteEvents.cs:58] UnityEngine.EventSystems.ExecuteEvents:Execute (UnityEngine.EventSystems.IPointerClickHandler,UnityEngine.EventSystems.BaseEventData) 0x0000024dccfd6f12 (Mono JIT Code) [ExecuteEvents.cs:272] UnityEngine.EventSystems.ExecuteEvents:Execute<T_REF> (UnityEngine.GameObject,UnityEngine.EventSystems.BaseEventData,UnityEngine.EventSystems.ExecuteEvents/EventFunction1<T_REF>) 0x0000024dccfdf6eb (Mono JIT Code) [StandaloneInputModule.cs:192] UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse (UnityEngine.EventSystems.PointerEventData,UnityEngine.GameObject) 0x0000024da9c43fc3 (Mono JIT Code) [StandaloneInputModule.cs:642] UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress (UnityEngine.EventSystems.PointerInputModule/MouseButtonEventData) 0x0000024da82dbfcb (Mono JIT Code) [StandaloneInputModule.cs:547] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent (int) 0x0000024da82dbe6b (Mono JIT Code) [StandaloneInputModule.cs:527] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent () 0x0000024da82db783 (Mono JIT Code) [StandaloneInputModule.cs:282] UnityEngine.EventSystems.StandaloneInputModule:Process () 0x0000024da8273acf (Mono JIT Code) [EventSystem.cs:504] UnityEngine.EventSystems.EventSystem:Update () 0x0000024dcadd7e58 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) 0x00007ff8d8eee4b4 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke 0x00007ff8d8e2e764 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke 0x00007ff8d8e2e8fc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke 0x00007ff7609edac4 (Unity) scripting_method_invoke 0x00007ff7609e8644 (Unity) ScriptingInvocation::Invoke 0x00007ff7609b62b4 (Unity) MonoBehaviour::CallMethodIfAvailable 0x00007ff7609b63bc (Unity) MonoBehaviour::CallUpdateMethod 0x00007ff7604adbc8 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager> 0x00007ff7604b51aa (Unity) BehaviourManager::Update 0x00007ff7606c5cad (Unity) InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward 0x00007ff7606ac89c (Unity) ExecutePlayerLoop 0x00007ff7606ac973 (Unity) ExecutePlayerLoop 0x00007ff7606b25d9 (Unity) PlayerLoop 0x00007ff7615f99d9 (Unity) PlayerLoopController::UpdateScene 0x00007ff7615f7bdf (Unity) Application::TickTimer 0x00007ff761a437aa (Unity) MainMessageLoop 0x00007ff761a4805b (Unity) WinMain 0x00007ff762dcb42e (Unity) __scrt_common_main_seh 0x00007ff9442d54e0 (KERNEL32) BaseThreadInitThunk 0x00007ff94490485b (ntdll) RtlUserThreadStart

2

Invalid Layer Index '-1'
0x00007ff760ac930d (Unity) StackWalker::GetCurrentCallstack
0x00007ff760acffe9 (Unity) StackWalker::ShowCallstack
0x00007ff761a3d613 (Unity) GetStacktrace
0x00007ff7620d223d (Unity) DebugStringToFile
0x00007ff760e06656 (Unity) AnimatorControllerPlayable::ValidateLayerIndex
0x00007ff760e06408 (Unity) AnimatorControllerPlayable::ValidateGoToState
0x00007ff760e00f7d (Unity) AnimatorControllerPlayable::GotoStateInternal
0x00007ff760e00f16 (Unity) AnimatorControllerPlayable::GotoState
0x00007ff760da5a0d (Unity) Animator::GotoState
0x00007ff75fd8db69 (Unity) Animator_CUSTOM_Play
0x0000024dccfe11c4 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Animator:Play (UnityEngine.Animator,int,int,single)
0x0000024dccfe0f3b (Mono JIT Code) UnityEngine.Animator:Play (string,int,single)
0x0000024dccfe0e8b (Mono JIT Code) UnityEngine.Animator:Play (string)
0x0000024dccfe0beb (Mono JIT Code) [game.cs:38] game:Tap () 
0x0000024cfbba9879 (Mono JIT Code) UnityEngine.Events.InvokableCall:Invoke ()
0x0000024cfbba926b (Mono JIT Code) UnityEngine.Events.UnityEvent:Invoke ()
0x0000024dccfdfba3 (Mono JIT Code) [Button.cs:71] UnityEngine.UI.Button:Press () 
0x0000024dccfdfae3 (Mono JIT Code) [Button.cs:115] UnityEngine.UI.Button:OnPointerClick (UnityEngine.EventSystems.PointerEventData) 
0x0000024dccfdfa89 (Mono JIT Code) [ExecuteEvents.cs:58] UnityEngine.EventSystems.ExecuteEvents:Execute (UnityEngine.EventSystems.IPointerClickHandler,UnityEngine.EventSystems.BaseEventData) 
0x0000024dccfd6f12 (Mono JIT Code) [ExecuteEvents.cs:272] UnityEngine.EventSystems.ExecuteEvents:Execute<T_REF> (UnityEngine.GameObject,UnityEngine.EventSystems.BaseEventData,UnityEngine.EventSystems.ExecuteEvents/EventFunction`1<T_REF>) 
0x0000024dccfdf6eb (Mono JIT Code) [StandaloneInputModule.cs:192] UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse (UnityEngine.EventSystems.PointerEventData,UnityEngine.GameObject) 
0x0000024da9c43fc3 (Mono JIT Code) [StandaloneInputModule.cs:642] UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress (UnityEngine.EventSystems.PointerInputModule/MouseButtonEventData) 
0x0000024da82dbfcb (Mono JIT Code) [StandaloneInputModule.cs:547] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent (int) 
0x0000024da82dbe6b (Mono JIT Code) [StandaloneInputModule.cs:527] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent () 
0x0000024da82db783 (Mono JIT Code) [StandaloneInputModule.cs:282] UnityEngine.EventSystems.StandaloneInputModule:Process () 
0x0000024da8273acf (Mono JIT Code) [EventSystem.cs:504] UnityEngine.EventSystems.EventSystem:Update () 
0x0000024dcadd7e58 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ff8d8eee4b4 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke 
0x00007ff8d8e2e764 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke 
0x00007ff8d8e2e8fc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke 
0x00007ff7609edac4 (Unity) scripting_method_invoke
0x00007ff7609e8644 (Unity) ScriptingInvocation::Invoke
0x00007ff7609b62b4 (Unity) MonoBehaviour::CallMethodIfAvailable
0x00007ff7609b63bc (Unity) MonoBehaviour::CallUpdateMethod
0x00007ff7604adbc8 (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x00007ff7604b51aa (Unity) BehaviourManager::Update
0x00007ff7606c5cad (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
0x00007ff7606ac89c (Unity) ExecutePlayerLoop
0x00007ff7606ac973 (Unity) ExecutePlayerLoop
0x00007ff7606b25d9 (Unity) PlayerLoop
0x00007ff7615f99d9 (Unity) PlayerLoopController::UpdateScene
0x00007ff7615f7bdf (Unity) Application::TickTimer
0x00007ff761a437aa (Unity) MainMessageLoop
0x00007ff761a4805b (Unity) WinMain
0x00007ff762dcb42e (Unity) __scrt_common_main_seh
0x00007ff9442d54e0 (KERNEL32) BaseThreadInitThunk
0x00007ff94490485b (ntdll) RtlUserThreadStart

The code is for enabling random animation of dice falling from 1 to 6 I'm making a game for android if you can create or update my code, this is also welcome, the main thing is that it does not cause errors.

And yes, I recently started working with Unity and can you please describe the solution in more detail and how such an error appears

0 Answers
Related