Я хочу сделать кнопку, которая имеет действие «ВЫБОР», чтобы не загружать сцену напрямую.Я сделал игру с 3 комнатами, и я хочу, чтобы игрок выбрал комнату, а затем нажмите другую кнопку, чтобы начать играть (например, СТАРТ).Как я могу это сделать?
using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; [System.Serializable] public struct SceneButton { public Button Button; public string SceneName; public void TurnOn() { // Do what you want to indicate the button is selected // Animate it, change colour, .... } public void TurnOff() { // Do what you want to indicate the button is NOT selected // Animate it, change colour, .... } } // Attach this script to the gameObject you want // On an empty or the confirm button for instance public class SceneSelector : MonoBehaviour { // Fill the array in the inspector [SerializeField] private SceneButton[] sceneButtons; private int selectedButtonIndex = -1; private void Start() { SetupButtons(); } private void SetupButtons() { for ( int i = 0 ; i < sceneButtons.Length ; ++i ) { int index = i; sceneButtons[i].Button.onClick.AddListener( () => SelectButton( index ) ); } } public void SelectButton( int buttonIndex ) { if ( selectedButtonIndex >= 0 ) sceneButtons[selectedButtonIndex].TurnOff(); selectedButtonIndex = buttonIndex; if ( selectedButtonIndex >= 0 ) sceneButtons[selectedButtonIndex].TurnOn(); } // Use this function as a callback of your button's `onClick` // used to confirm the choice of the user public void LoadSelectedScene() { if ( selectedButtonIndex >= 0 ) { SceneManager.LoadScene( sceneButtons[selectedButtonIndex].SceneName ); } } }