FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál

Only 1 out of 3 Animator components react to trigger event

I have a main menu in which I want buttons to play an animation when they are held pressed and only fire it's "OnClick()" event when the animation ends. (So it's reset if you do not hold it long enough)

enter image description here

I have 3 identical Animator components, 1 for each button :

enter image description here

Here you can see my animator controller:

enter image description here

When the button is pressed I change "NoTrigger" to "PressedTrigger". I checked if that works for every button individually while the game was running in editor - The triggers change properly. However, if it will be needed, here is my code of the button press (I use custom controller so there cannot be any Input system mumbo-jumbo):

        if (JStepData?.RightButton == 0 && JStepData?.LeftButton == 1 || Input.GetButtonDown(GameConstants.k_ButtonNameSubmit))
        {
            if (prevRightButton == 0)
            {
                return;
            }
            Animator anim = leftMenuButtons.GetChild(currentButtonSelected - 1).gameObject.GetComponent<Animator>();

            Button currentButton = leftMenuButtons.GetChild(currentButtonSelected - 1).gameObject.GetComponent<Button>();
            Debug.Log("Animator Normalized Time: " + anim.GetCurrentAnimatorStateInfo(0).normalizedTime);
            if (!animationStarted)
            {
                //leftMenuButtons.GetChild(currentButtonSelected - 1).gameObject.GetComponent<Button>().
                anim.SetTrigger("PressedTrigger");
                anim.ResetTrigger("NoTrigger");
                animationStarted = true;
            }
            if (anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1)
            {
                Debug.Log("CLICK!");
                //Debug.Log("Animator Normalized Time: " + anim.GetCurrentAnimatorStateInfo(0).normalizedTime);
                currentButton.onClick.Invoke();
            }
            prevRightButton = 0;
        }
        else
        {
            Animator anim = leftMenuButtons.GetChild(currentButtonSelected - 1).gameObject.GetComponent<Animator>();
            anim.ResetTrigger("PressedTrigger");
            anim.SetTrigger("NoTrigger");
            animationStarted = false;
        }

As for now the code works somewhat only for the first button. The animation starts at the start of the scene and cycles "Empty State" which makes normalized time surpass 1 even before I have a chance to press the button. (So that's the problem too, but it's not the main one.)

When I press any other button the animator only changes the trigger value, but the animator controller does not do anything. It does not even cycle "Empty State". If I play the animation raw in the animation tab in editor every animation seems to work properly. So it seems like the 2 other buttons just do not even start their controllers or something.
I'm also pretty sure I'm accessing proper animator components because their normalized time is 0.

I don't really know what is going on here and why this behavior occurs. I would appreciate any help.

❌
❌