실행 이미지

 

설정 1
설정 2

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

public class UIAnimationMain : MonoBehaviour
{
    [SerializeField] private Transform point;   //보스의 게이지 위치 (월드상)
    [SerializeField] private Transform bossGauge;
    [SerializeField] private Canvas canvas;

    void Start()
    {


    }

    void Update()
    {
        //Canvas 의 Render Mode가 Overlay일경우 
        //월드 위치를 스크린 위치로 변환 
        Vector2 screenPosition = Camera.main.WorldToScreenPoint(point.position);

        //스크린 좌표를 -> Canvas의 RectTransform로컬좌표로 변환 
        RectTransform canvasRectTransform = canvas.GetComponent<RectTransform>();
        Vector2 canvasLocalPosition;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, screenPosition, null, out canvasLocalPosition);

        Debug.Log(canvasLocalPosition);
        bossGauge.localPosition = canvasLocalPosition;
    }
}

UIAnimationMain.cs

+ Recent posts