๐ŸŽฎ Unity Study/Unity

[Unity] Button onClick.AddListener

ibelieveinme 2024. 2. 16. 15:26
728x90

 

AddLisener ๋กœ ๋ฒ„ํŠผ์— ์ด๋ฒคํŠธ ํ• ๋‹นํ•˜๊ธฐ

 

1. ์ธ์ž๊ฐ€ ์—†๋Š” ๋ฉ”์„œ๋“œ ์ผ ๋•Œ

void Awake()
{
    button.onClick.AddListener(PressBtn);
}

void PressBtn()
{
}

 

 

2. ์ธ์ž ์žˆ๋Š” ๋ฉ”์„œ๋“œ ์ผ ๋•Œ

void Awake()
{
    button.onClick.AddListener(() => OpenPopup("Title"));
    button.onClick.AddListener(delegate { OpenPopup("Title"); });
}

void OpenPopup(string title)
{
}

์ธ์ž๊ฐ€ ์žˆ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ๋Š” ๋žŒ๋‹ค์‹์ด๋‚˜ ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

 

 

* ์ฐธ๊ณ 

https://docs.unity3d.com/2018.3/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

 

728x90