Ad Block 한번만 꺼주시면 안될까요..?
게임 개발/유니티C#

유니티 C#) 선택된 UI 가져오는 법. (EventSystem.current.currentSelectedGameObject)

UniCoti(유니코티) 2023. 1. 25.

이번엔 유니티에서 클릭한(선택한) UI를

가져오는 방법에 대해 알아보도록 하겠다.

 사실 이름이 조금 길 뿐이지 별거 없다.

 


바로 시작하자.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;


public class GameManager : MonoBehaviour {
    public GameObject SelectedObject = null;
	
    Update() {
	SelectedObject = EventSystem.current.currentSelectedGameObject;
    }
}

일단 선택한 UI를 가져오는 실질적인 코드는

EventSystem.current.currentSelectedGameObject이다.

 

이름이 굉장히 길지만, 이걸 사용하기 위해선,

맨 위쯤에 있는 using문을 꼭 사용해줘야 한다.

 

using UnityEngine.EventSystems;

를 적어 주어야만 저 메서드를 사용할 수 있다.

이점에 주의하자.

 

요약 : EventSystem.current.currentSelectedGameObject

 

유니티 협력 글(어필리에이트)


이상으로 도움이 되었길 바라며,

 

끝.

댓글

💲 추천 글