Unity

[Unity] 유니티 월드좌표의 타겟 오브젝트 좌표에 맞게 UI(Canvas)의 좌표에 소스 오브젝트 인스턴스화 하기. The source object instance to the coodinates of the UI(Canvas) for the target object coordinate of the coordinate ..

정보처리마법사 2017. 2. 23. 02:12
반응형

[Unity] 유니티 월드좌표의 타겟 오브젝트 좌표에 맞게 UI(Canvas)의 좌표에 소스 오브젝트 인스턴스화 하기. The source object instance to the coodinates of the UI(Canvas) for the target object coordinate of the coordinate world coordinates. Convert from world space to canvas space



유니티 Convert from world space to canvas spase.

 

안녕하세요 정보처리마법사 입니다.

 

이번 포스팅의 주제는 월드좌표와 캔버스좌표에 관한 내용입니다.

마킹한 부분이 사용하는 부분입니다. 

위 상황을 설명 드리자면, 이동하는 플레이어의 월드좌표에 맞게 UI(Canvas)에서 데미지 수치 프리팹을 인스턴스화 하는 내용입니다.

소스코드를 더 간결하게 할 여지가 많은데, 하지 않은 상태입니다. 

참고하시어 응용하시면 되겠습니다.


소스코드 입니다.

1
2
3
4
5
6
        RectTransform CanvasRect = GameObject.Find("Canvas").GetComponent<RectTransform>();
        Vector2 ViewportPosition = Cam.WorldToViewportPoint(GameObject.Find("P").transform.position);
        Vector2 WorldObject_ScreenPosition = new Vector2(
        ((ViewportPosition.x * CanvasRect.sizeDelta.x) - (CanvasRect.sizeDelta.x * 0.5f)),
        ((ViewportPosition.y * CanvasRect.sizeDelta.y) - (CanvasRect.sizeDelta.y * 0.5f)));
        damage_effect.GetComponent<RectTransform>().anchoredPosition = WorldObject_ScreenPosition;
cs


 

 

이상으로 포스팅을 마칩니다. 감사합니다.






Fin.


잘 못 된 정보가 있으면 말씀해주세요~


공감버튼 클릭은 작성자에게 큰 힘이 됩니다.  행복한 하루 되세요.


 


반응형