짱이 될거야
Unity 3D Minimap: v1. Live map(3D) 본문
프로젝트 초기 설정
1. 프로젝트 생성
2. GameObject > 3D Object > Plane 생성
3. GameObject > 3D Object > Cube 생성 (character 될 예정)
4. Assets/Images 폴더 생성 후 free image 다운로드 (plane에 삽입)
미니맵 초기 설정
1. 2D로 바꾸고 Canvas 생성
2. Canvas > 우클릭 > UI > Image (Minimap)
- Size: 110, 110
- 위치: 오른쪽 아래
- 미니맵을 넣을 껍데기
3. Canvas/Minimap > 우클릭 > UI > Raw Image (Map Image) 생성
4. Assets/Images 폴더 안에서 우클릭 > Create > Render Texture (MiniMapRT)
5. MiniMapRT Inspector 설정
- Size: MapImage 사이트와 동일하게 설정
- Depth Stencil Format: None
6. Canvas/Minimap/MapImage Texture에 MiniMapRT 넣기
미니맵 카메라 설정
GameObject > Camera (MiniMap_Camera) 생성
- Projection: Orthographic
- Size: 12
- Target Texture: MiniMapRT
캐릭터 이동 설정
Cube를 캐릭터라고 간주하고, 키보드 방향키에 따른 이동 설정
MoveController.cs 파일 만들고 Cube에 drag & drop
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveController : MonoBehaviour
{
public GameObject cube;
public float speed = 0.1f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.UpArrow))
{
this.transform.Translate(0, 0, speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.RightArrow))
{
this.transform.Translate(speed * Time.deltaTime, 0, 0);
}
if (Input.GetKey(KeyCode.DownArrow))
{
this.transform.Translate(0, 0, -speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
this.transform.Translate(-speed * Time.deltaTime, 0, 0);
}
}
}
미니맵 Script
Assets/Scripts MinimapCamera.cs 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MinimapCamera : MonoBehaviour
{
public Transform Player;
public Camera MainCamera;
public bool RotateWithPlayer = true;
// Start is called before the first frame update
void Start()
{
SetPosition();
SetRotation();
}
void LateUpdate()
{
if (Player != null)
{
SetPosition();
if (RotateWithPlayer && MainCamera)
{
SetRotation();
}
}
}
private void SetRotation()
{
transform.rotation = Quaternion.Euler(90.0f, MainCamera.transform.eulerAngles.y, 0.0f);
}
private void SetPosition()
{
var newPos = Player.position;
newPos.y = transform.position.y;
transform.position = newPos;
}
}
Minimap_Camera 컴포넌트 안에 MinimapCamera.cs 스크립트를 넣는다.
Player와 Main Camera에 각 컴포넌트를 drag & drop 해서 넣는다.
Main Camera를 character 컴포넌트 안에 넣으면 캐릭터를 따라가면서 카메라를 비춘다.
참고
https://www.youtube.com/watch?v=ZZD1cg8xDsI&t=395s
'프로젝트' 카테고리의 다른 글
Unity 2D Fade In/Out (0) | 2022.10.28 |
---|---|
Unity 3D Minimap: v2. Fixed map(2D) (0) | 2022.10.27 |
Unity 팝업창 제작 (3D에서 2D 버튼 만들기) (0) | 2022.10.26 |
Unity 설치 가이드 (0) | 2022.10.25 |
Vuex: url 새 탭으로 열기 (1) | 2022.10.05 |