프로젝트/건즈앤 레이첼스
[유니티 프로젝트] 로그라이크 허브 마을 (기억의 성소) 제작 .2 (레이어 정리 및 월드 팝업 UI)
Bueong_E
2023. 4. 16. 22:39
반응형
SMALL
- 추가사항
- 레이어 수정으로 좀 더 자연스러운 sorting layer
- NPC 혹은 디파짓 빌보드등 유저가 상호작용 해야하는 월드 스크린 UI
- 기사단의 colier 조정으로 유저의 동선 방해 요소 제거
- 월드 스크린 UI 설정
캔버스 설정을 World Space로, 이렇게 하면 월드 좌표상으로 UI의 위치가 변경된다.
(카메라와의 이벤트 인터렉션이 따로 없어 지정을 해주지는 않았으나 혹 카메라에 관련된 이벤트가 존재한다면 메인 카메라 등 카메라를 할당해주어야 한다.)
UI크기가 줄어들시 레거시 버튼 혹은 text 등은 월드 좌표상에서 크기가 줄어들면 깨지거나 뭉개져 보일수 있기 때문에 TextMesh Pro 를 사용이 필요했다.
- 스크립트
스크립트에는 OnTriggerEnter2D (Exit) 을 이용해 일정 범위 안에 유저가 들어오면 UI 팝업을 뜨게 만들었다.
이떄 각 객체들은 자신의 이름 , 및 포지션을 gamemain에게 보내고 현재는 게임 메인이 UI를 가지고 있으나 나중에는 성소 씬 UI 디렉터가 해당 UI 를 팝업 시킬 예정이다.
현재까지는 UI는 생각보다 자연스럽게 전개 되는 듯 하고 실사용 테스트로 유저가 어느정도 인터렉션이 편리한지 안한지는 확인해 보아야할듯 하다.
SanturarySceneMain 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SanturarySceneMain : MonoBehaviour
{
private Camera mainCam;
public System.Action<string,Vector3> onPopUp;
[SerializeField]
private GameObject player;
[SerializeField]
private GameObject popup;
private RectTransform popupRect;
private void Awake()
{
this.mainCam = Camera.main;
this.onPopUp = (npcName,npcPos) =>
{
this.popup.transform.position = new Vector3(npcPos.x,npcPos.y+2,-10);
this.popup.SetActive(!this.popup.activeSelf);
};
}
private void LateUpdate()
{
Vector3 playerPos = new Vector3(this.player.transform.position.x, this.player.transform.position.y, -11);
this.mainCam.transform.position = playerPos;
}
}
NPCController 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NPCController : MonoBehaviour
{
[SerializeField]
SanturarySceneMain SanturarySceneMain;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.transform.gameObject.tag == "Player")
{
this.SanturarySceneMain.onPopUp(this.gameObject.name, this.transform.position);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.transform.gameObject.tag == "Player")
{
this.SanturarySceneMain.onPopUp(this.gameObject.name, this.transform.position);
}
}
}
반응형
LIST