Question by
The_ZayNepz_Guy · Jun 02 at 03:20 PM ·
uibutton
Why does my button only work once?
Hey, I'm using unity's new UI Builder and toolkits so there's not a lot of info on the topic. But I have all buttons working and functioning like they should, except every button on every gameobject (setting layers) works only once. Any help appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
public class UI_input_manager : MonoBehaviour
{
public Button buttonSingle;
public Button buttonMulti;
public Button buttonSettings;
public Button buttonAbout;
public Button buttonQuit;
public GameObject About;
public GameObject Setting;
public GameObject Home;
void Start()
{
var root = GetComponent<UIDocument>().rootVisualElement;
buttonSingle = root.Q<Button>("singleplayer");
buttonMulti = root.Q<Button>("multiplayer");
buttonSettings = root.Q<Button>("settings");
buttonAbout = root.Q<Button>("about");
buttonQuit = root.Q<Button>("quit");
buttonSingle.clicked += StartSingle;
//buttonMulti.clicked += StartMulti;
buttonSettings.clicked += OpenSettings;
buttonAbout.clicked += ShowAbout;
buttonQuit.clicked += QuitGame;
}
void StartSingle()
{
SceneManager.LoadScene(2);
}
void QuitGame()
{
Application.Quit();
Debug.Log("Exit game");
}
void OpenSettings()
{
Home.SetActive(false);
Setting.SetActive(true);
}
void ShowAbout()
{
About.SetActive(true);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to change a button image with script? 1 Answer
Updating Button Text 0 Answers
UI Buttons Trigger displaced after build. Help Please 0 Answers
UI in World Space doesn't respond 1 Answer
UI in the end of the scene 0 Answers