UNITY/Unity Study

플레이어 따라다니는 텍스트 만들기

GREEN나무 2023. 8. 14. 13:44
728x90

https://youtu.be/R2yhLfENJnk

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class FollowText : MonoBehaviour
{
    public Transform playerHead; // 플레이어 오브젝트
    public TMP_Text textToFollow; // 따라다닐 TMP Text 오브젝트

    private void Update()
    {
        // 플레이어 머리 위치로 TMP Text 위치를 업데이트합니다.
        if (playerHead != null && textToFollow != null)
        {
            Vector3 offset = new Vector3(-6.0f, 2.0f, -3.6f);
            // 텍스트와의 거리 조정
            textToFollow.transform.position = playerHead.position + offset;
        }
    }
}

프리펨 안에

새 UI  캔버스 만들어서 

 Render Mode를 World Space

 Event Camera에 카메라 넣기

TMP에 위 코드 넣고 

  Vector3 offset = new Vector3( 위치 맞추기);

'UNITY > Unity Study' 카테고리의 다른 글

박스미는 만큼 HP 깎기  (0) 2023.08.19
Roulette  (0) 2023.08.14
계단에서 굴러떨어짐 고치기  (0) 2023.08.05
플레이어 계단 오르내리기(씬 이동) - Unity, 3D  (0) 2023.08.05
게임 인트로화면 만들기  (2) 2023.08.03