When a button is pressed once, it will change to highlighted color until mouse button is pressed outside this button.
In my case, each button link to an 3d objects in scene. If the link is null, i dont want the button to stay in highlighted color.
So, how to remove the pressed condition of a button in script?
Pretty sure you would change its colour to the “normal” colour (from the colors part of Button/Selectable).
Shitman
December 4, 2017, 12:49pm
3
I finally use “eventsystem selected object set null” on button script.
ah ya, cool, that works, too Didn’t think of that until you mentioned it.
lmahieu
February 2, 2023, 10:18am
5
If someone still got the issue, here is the fix:
using UnityEngine.EventSystems;
if (EventSystem.current.currentSelectedGameObject == _myButton.gameObject)
{
EventSystem.current.SetSelectedGameObject(null);
}
Also you need to have an EventSystem in your scene
3 Likes