본문 바로가기
PROGRAMING📚/Unity📑

[유니티 Unity] 클릭한 버튼(Button) 오브젝트 이름 가져오기

별찌루 2022. 11. 24.
728x90
반응형

 

클릭한 버튼 오브젝트와 오브젝트 이름 가져오기

 

 

 

 

버튼을 클릭했을 때 , 해당 오브젝트의 이름에 따라서

동작하는 방법을 찾다가 클릭하는 오브젝트의 이름을 받아서

이름에 따라 조건을 주어서 이벤트를 발생하는 방법을 사용하게 되면서

다음과 같이 EventSystem.current.currentSelectedGameObject 를 사용해주었다.

 

 

 

using UnityEngine.EventSystems;

public class Button : MonoBehaviour
{
	// 버튼 이름 가져오기
	public void GetButtonName()
    {
		string EventButtonName = EventSystem.current.currentSelectedGameObject.name;
	}
    // 버튼 오브젝트 가져오기
	public void GetButtonName()
    {
		GameObject EventButtonOb = EventSystem.current.currentSelectedGameObject;
	}
}

 

 

 

출처 : https://sakriun-0507.tistory.com/entry/Unity-%ED%81%B4%EB%A6%AD%ED%95%9C-%EC%98%A4%EB%B8%8C%EC%A0%9D%ED%8A%B8%EB%B2%84%ED%8A%BC%EC%9D%98-%EC%9D%B4%EB%A6%84-%EA%B0%80%EC%A0%B8%EC%98%A4%EA%B8%B0

728x90
반응형

댓글