Created
April 30, 2025 02:00
-
-
Save Ddemon26/19793c515309d0eaadfb9d7c274bd8f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class NewMonoBehaviourScript : MonoBehaviour { | |
public List<Button> buttons = new List<Button>(); | |
void Awake() { | |
foreach (var button in buttons) { | |
button.onClick.AddListener( OnButtonClick ); | |
} | |
} | |
void OnButtonClick() { | |
//log the position in the list of the button that was clicked | |
int index = buttons.IndexOf | |
( | |
(Button)UnityEngine.EventSystems | |
.EventSystem.current.currentSelectedGameObject | |
.GetComponent<Button>() | |
); | |
Debug.Log( "Button clicked: " + index ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment