우리는 당신의 질문을 이해한다면,이 작업을해야합니다
를이 방법은 당신이 세계 위치에서 캔버스의 위치를 화면 제공 :
public static Vector3 GetScreenPositionFromWorldPosition(Vector3 targetPosition)
{
Vector3 screenPos;
screenPos = Camera.main.WorldToScreenPoint(targetPosition);
return new Vector3 (screenPos.x, screenPos.y, 0f);
}
다음 전원 막대 위에 스크립트가 필요합니다.
public class PowerBar : MonoBehaviour
{
public Transform target;
RectTransform _rectTransform;
void Awake()
{
_rectTransform = GetComponent<RectTransform>();
}
public void updatePosition()
{
Vector3 pos = YourStaticClassWith.GetScreenPositionFromWorldPosition (target.position);
Vector2 rpos = pos;
_rectTransform.anchoredPosition3D = rpos + Vector2.up * 100f; // 100f is value of how many pixels above the target that UI element should apear
}
void LateUpdate()
{
updatePosition();
}
}
target
은 기본적으로 플레이어 개체의 transform
입니다.
100f
값은 대상보다 큰 픽셀을 나타냅니다.
이미지로도 이해하기 어려운 질문입니다. 그것을 다시 시도하십시오. UI에 어떤 문제가 있습니까? 무엇을하고 싶니? – Programmer
@Programmer 나는 그들이 화면 주위를 움직일 때 플레이어 오브젝트 위에 플레이어의 UI 파워 바를 따라 가려고한다고 믿는다. WorldSpace 캔버스를 사용하거나 3D 텍스처를 사용해야 할 수도 있습니다. 명확한 설명이 도움이 될 것입니다. – ejsd1989
정확히 맞았습니다. 문제의 나쁜 표현을 유감스럽게 생각하고, 어떻게 말을해야할지 몰랐습니다. – Brad094