Hi!
Context:
I use SF UI Sample (Unity Technology) from the asset store and I want to use buttons to make toggles in a UI Settings.
So a click on “Settings” menu on Mainmenu disable (using SetActive) Mainmenu and enable UI Settings.
One of those settings is the timer for a game session with 3 choses : 30, 60 or 90 seconds.
I create an empty gameobject, rename as TimerSettings that is my Toggle Group and contains 3 buttons. Then, I remove the Button component to add the Toggle component and set isOn on 60 as default. Interactable checked and transition with animation Set. Animator set with SF Button animation from the asset. In this animation, I just change the Pressed State motion to Normal motion.
Then, I create a script to trigger the Selected state animation (Pressed motion) when Toggle isOn. When isOn is false, I resetTrigger Selected and set trigger Normal (Normal motion).
Problem:
From here, it works fine when it’s the first time UI Settings is enable. When I click on 90 option, the animation triggered Selected and I see the pressed motion an the 60 option trigger Normal state and showing the normal motion and the good color.
But, when I go back to the Mainmenu (disable UI Settings enable Mainmenu) and return to the settings, and choose another option than 90, the other works fine but the 90 stay in pressed motion color.
Script:
Toggle toggle;
Animator animtor;
bool reseted = true;
void Start()
{
toggle = GetComponent<Toggle>();
animator = GetComponent<Animator>();
//EventSystem.current.SetSelectedGameObject(null);
}
void Update()
{
ToggleSelectedState();
}
public void ToggleSelectedState()
{
if (toggle.isOn)
{
animator.SetTrigger("Selected");
reseted = false;
}
else if(!toggle.isOn && !reseted)
{
//toggle.enabled = false;
//toggle.enabled = true;
//animator.Rebind()
animator.ResetTrigger("Selected");
animator.SetTrigger("Normal");
reseted = true;
//EventSystem.current.SetSelectedGameObject(null);
}
Solutions tried:
Like you see in my script in comments, I tried many solutions I found on websearch but nothing worked. I also tried to override the color in Normal motion but nothing changed…
Any idea?