world to ngui
Unity3D 2015. 10. 2. 17:071 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using System.Collections; using System.Collections.Generic; using UnityEngine; using HedgehogTeam.EasyTouch; public class TestMain : MonoBehaviour { public UIJoystick joystick; public UIRoot uiRoot; void Start () { EasyTouch.On_TouchStart += EasyTouch_On_TouchStart; } private void EasyTouch_On_TouchStart(Gesture gesture) { var pos = UICamera.mainCamera.ScreenToWorldPoint(gesture.position); pos = UICamera.mainCamera.WorldToScreenPoint(pos); this.joystick.transform.localPosition = pos; } // Update is called once per frame void Update () { } } | cs |
// world to ngui
var target = GameObject.Find("LeftGate");
Camera worldCam = NGUITools.FindCameraForLayer(target.layer);
Camera guiCam = NGUITools.FindCameraForLayer(uiBinds.Indicators.HouseIcon.layer);
var pos = guiCam.ViewportToWorldPoint(worldCam.WorldToViewportPoint(target.transform.position));
pos.z = 0;
uiBinds.Indicators.HouseIcon.transform.position = pos;
// end
//방법1
var pos = UICamera.mainCamera.ScreenToWorldPoint(gesture.position);
pos = UICamera.mainCamera.WorldToScreenPoint(pos);
//방법2
var target = GameObject.Find("LeftGate");
Camera worldCam = NGUITools.FindCameraForLayer(target.layer);
Camera guiCam = NGUITools.FindCameraForLayer(uiBinds.Indicators.HouseIcon.layer);
var pos = guiCam.ViewportToWorldPoint(worldCam.WorldToViewportPoint(target.transform.position));
pos.z = 0;
uiBinds.Indicators.HouseIcon.transform.position = pos;
//방법3
Vector3 mainCamera_ScreenPos = Camera.main.WorldToScreenPoint(world_pos);
Vector3 uiCamera_WorldPos = UICamera.mainCamera.ScreenToWorldPoint(mainCamera_ScreenPos);
Camera worldCam = NGUITools.FindCameraForLayer(LayerMask.NameToLayer("player"));
//GUI객체의 카메라 객체입니다.
Camera guiCam = NGUITools.FindCameraForLayer(LayerMask.NameToLayer("UI"));
//타겟의 포지션을 월드좌표에서 ViewPort좌표로 변환하고 다시 ViewPort좌표를 NGUI월드좌표로 변환합니다.
Vector3 pos = guiCam.ViewportToWorldPoint(worldCam.WorldToViewportPoint(initPoint.transform.position));
//Z는 0으로...
pos.z = 0f;
//Label의 좌표를 설정합니다.
hud.transform.position = pos;
hud.gameObject.SetActive(true);
'Unity3D' 카테고리의 다른 글
[벡터 내적] 플레이어와 몬스터가 있을때 몬스터가 앞에 있는지 뒤에 있는지 알아내는 방법 (0) | 2016.01.05 |
---|---|
유니티 안드로이드 텍스쳐 포맷 (Unity Android Texture Format) 의 비밀 (0) | 2015.10.06 |
Text 한글자씩 나오게 하는 방법. (0) | 2015.08.31 |
NGUI position to World position (0) | 2015.08.27 |
Linear Translation (0) | 2015.08.27 |