UNITY/Unity Study

목표에 도달하면 팝업창 띄우기

GREEN나무 2023. 8. 1. 15:04
728x90

플레이어에 넣기

using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public Transform targetPosition;
    public float popupDistanceThreshold = 2f;
    public GameObject popupPanel;

    private void Update()
    {
        if (targetPosition == null || popupPanel == null)
        {
            Debug.LogError("Please assign the target position and popup panel in the Inspector.");
            return;
        }

        float distanceToTarget = Vector3.Distance(transform.position, targetPosition.position);

        if (distanceToTarget <= popupDistanceThreshold)
        {
            popupPanel.SetActive(true);
        }
        else
        {
            popupPanel.SetActive(false);
        }
    }
}

플레이어에 PlayerController.cs.를 넣고 

하이라키에서

targetPositio에는 도달하려는 객체를

popupPanel는 팝업창을 넣는다.

 

 

 

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

한글 폰트 사용하기  (0) 2023.08.02
버튼 눌러 팝업창 넘기기  (0) 2023.08.02
해결 - 따로 돌릴 땐 됐는데 합치니 제 기능을 못 함  (0) 2023.07.31
애셋배치-학교  (0) 2023.07.29
프리펩 해제하기  (0) 2023.07.28