- Home /
Wrong current selected game object when pressing a button
I have a button with a listener for the following script
public void UseItem()
{
Debug.Log(EventSystem.current.currentSelectedGameObject.ToString());
int place = EventSystem.current.currentSelectedGameObject.GetComponent<EquipSlot>().place;
Vector3 shotdir = player.GetComponent<TDPlayerController>().moveDir;
}
}
The place variable is used to tell which button is being pressed (multiple buttons with this listener) There is also a button a considerable distance below it, and for some reason when the camera moves up and down the button below it becomes the selected game object and I get an error because it tries to get the place variable from it. A simple solution would be checking if the gameobject has the script, but I'm not understanding why a button so far below is being selected
Your answer
Follow this Question
Related Questions
UI Button not sending event on IOS build only 1 Answer
UI: Mouse events not working 1 Answer
Event system or UI Button ? 0 Answers
How to set UI button as selected on mouse over 1 Answer
UI button always selected? 0 Answers