


그리고 유니티에서는 이 기능을 아주 간단하게 제공한다. 버튼의 Inspector에서 버튼이 클릭되었을 때 할 일을 정해주는 OnClick() 부분을 추가(+)한다. 그리고 그 버튼에 해당하는 판넬을 None이라고 되어 있는 칸에 드래그해서 넣어준다!
마지막으로, No Function이라고 되어 있는 칸RectTransform>SetAsLastSibling 으로 바꿔준다!
맵 버튼을 누르면 하이라키 맨 밑에 배치하여 해당 이미지를 제일 먼저 보여주기

퀘스트 버튼을 누르면 하이라키 맨 밑에 해당 이미지를 배치하여 제일 먼저 보여주기

영혼낙인 버튼을 누르면 하이라키 맨 밑에 해당 이미지를 배치하여 제일 먼저 보여주기

영혼의 영혼낙인 버튼을 누르면 하이라키 맨 밑에 해당 이미지를 배치하여 제일 먼저 보여주기

Status 버튼을 누르면 하이라키 맨 밑에 해당 이미지를 배치하여 제일 먼저 보여주기

옵션 버튼을 누르면 하이라키 맨 밑에 해당 이미지를 배치하여 제일 먼저 보여주기



먼저, 지도 버튼이 첫번째 이므로 버튼의 이미지를 파란색으로 설정한다.

UIManager라는 빈 객체 만들고 UIManager 스크립트 추가

using UnityEngine;
using UnityEngine.UI;
public class UIManager : MonoBehaviour
{
public Button[] TabButtons;
private bool isChoose = false;
public void ColorChange(Button clickedButton)
{
isChoose = !isChoose;
foreach(Button button in TabButtons)
{
Image buttonImage = button.GetComponent<Image>();
if (button == clickedButton)
{
// 클릭된 버튼은 파란색
buttonImage.color = Color.blue;
}
else
{
// 나머지 버튼은 검은색
buttonImage.color = Color.black;
}
}
}
}














using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UIManager : MonoBehaviour
{
public Button[] TabButtons;
EventSystem system; //⭐
public Selectable firstInput; //⭐
private Button lastSelectedButton; //⭐마지막으로 선택된 버튼
void Start()
{
system = EventSystem.current; //⭐
if (TabButtons != null && TabButtons.Length > 0) //⭐
{
TabButtons[0].Select(); //⭐ 첫 번째 버튼 선택
lastSelectedButton = TabButtons[0]; //⭐
ColorChange(lastSelectedButton); //⭐ 초기 색상 설정
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
NavigateButtons(true);
}
else if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("E");
NavigateButtons(false);
}
}
private void NavigateButtons(bool isShiftPressed)//⭐
{
// 현재 선택된 Selectable 가져오기
Selectable current = system.currentSelectedGameObject?.GetComponent<Selectable>();//⭐
if (current == null && lastSelectedButton != null) //⭐마우스로 빈 공간 선택시 current가 null이므로, null일 경우
{
lastSelectedButton.Select(); //⭐마지막 버튼 선택
current = lastSelectedButton; //⭐마지막으로 버튼을 current에 저장.
}
if (current != null) //⭐
{
Selectable next = isShiftPressed ? current.FindSelectableOnLeft() : current.FindSelectableOnRight(); //⭐ true/false에 따른 왼쪽 이동과 오른쪽이동.
if (next != null) //⭐
{
Debug.Log("2");
next.Select();//⭐
Button nextButton = next.GetComponent<Button>(); //⭐선
if (nextButton != null && nextButton != lastSelectedButton)//⭐
{
Debug.Log("3");
nextButton.onClick.Invoke(); //⭐
lastSelectedButton = nextButton; //⭐마지막 선택된 버튼 업데이트
}
}
}
}
public void ColorChange(Button clickedButton)
{
foreach(Button button in TabButtons)
{
Image buttonImage = button.GetComponent<Image>();
if (button == clickedButton)
{
// 클릭된 버튼은 파란색
buttonImage.color = Color.blue;
}
else
{
// 나머지 버튼은 검은색
buttonImage.color = Color.black;
}
}
}
}


마지막 버튼인 옵션 버튼도 마찬가지로 한다.







