티스토리 뷰
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UiMainScene : MonoBehaviour
{
public UiCaptian uicap;
void Start()
{
this.uicap.onClick = (btn) => {
Debug.Log(btn);
};
}
}
#UiCaptain=>UiMainScene (Debug.Log 로 출력)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UiCaptian : MonoBehaviour
{
public enum eBtnType
{
Yellow,
Green,
Blue
}
public Button[] btns;
public System.Action<eBtnType> onClick;
void Start()
{
for(int i=0; i<btns.Length; i++)
{
int index = i;
btns[index].onClick.AddListener(() => {
this.onClick((eBtnType)index);
});
}
}
}
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/Events.UnityEvent.AddListener.html
Unity - Scripting API: Events.UnityEvent.AddListener
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see: You've told us there are code samples on this page which don't work. If you know ho
docs.unity3d.com
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Button-onClick.html
Unity - Scripting API: UI.Button.onClick
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see: You've told us there are code samples on this page which don't work. If you know ho
docs.unity3d.com
'게임클라이언트 프로그래밍 > Unity' 카테고리의 다른 글
UI Animation (0) | 2023.02.09 |
---|---|
Unity TabButton (0) | 2023.02.08 |
Unity toggle (1) | 2023.02.07 |
버튼 UI (0) | 2023.02.07 |
Unity 2D Shooting (0) | 2023.02.05 |