티스토리 뷰

게임클라이언트 프로그래밍/Unity

Unity Button

Game Client Lee Hwanguk 2023. 2. 8. 00:58
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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함