- Home /
How do I stop EventSystem.currentSelectedGameObject from changing on a button press
I am building the UI menu system for my game and one thing I want to do is let the player choose between a list of servers that are active and then click a "Connect" button to join that server.
Right now the user can click on a server (my servers are buttons with three Text children for GameName, GameInfo, and #of connected players) and that server becomes the EventSystem.currentSelectedGameObject which is what I want. The problem happens when they click the Connect Button because the Connect button becomes the EventSystem.currentSelectedGameObject before running my OnConnectButtonClick() method. The code is below.
public void OnConnectButtonClick()
{
Debug.Log ("Connect Button Clicked");
string password = joinServerPasswordInput.text;
Debug.Log (eventSystem.currentSelectedGameObject.name);
string hostGUID;
hostGUID = eventSystem.currentSelectedGameObject.GetComponent<ServerListButtonScript>().hostForThisButton.guid;
Network.Connect (hostGUID, password);
}
The Debug.Log is "Connect Button"
Your answer
Follow this Question
Related Questions
How to make Buttons communicate with UDP 2 Answers
Is it wise to add scripts to Unity's Event System? 0 Answers
EventSystem.SetSelectedGameObject Does not display highlight animations for my buttons 1 Answer
How to send mouse events directly to the canvas in world pos 0 Answers
Adding single Event listener to multiple ui buttons via scripting 1 Answer