3D 캐릭터위에 2D 이미지(HP바라던지)를 구현 해야할 때가 있습니다.
아래와 같이 구현하면 됩니다.
// transform.position = 3D Character position Vector3 v3 = Camera.mainCamera.WorldToViewportPoint(transform.position); // NGUI Camera ViewportToWorldPoint Vector3 myMenuPos = GameObject.Find("InGameUIRoot/Camera").camera.ViewportToWorldPoint(v3); float x = myMenuPos.x; // x offset float y = myMenuPos.y +0.2f; // y offset float z = myMenuPos.z; // y offset // NGUI HPBar Position HpBar.transform.position = new Vector3(x,y,0);
그럼 그림과 같이 나오게 됩니다.
화면밖에 있을 때 해골표시등은 아래와 같이 예외처리 합니다.
// 화면밖에 있을 때 해골표시 예외 처리 if ( HpBar.transform.localPosition.y > GameSystem.ScreenScale().y ) // 스크린 사이즈 얻어오기 public static Vector3 ScreenScale() { Vector3 resultScale = Vector3.zero; float screenWidth = Screen.width; float screenHeight = Screen.height; //UIRoot에 지정한 Height값 float activeHeight = GameObject.Find("InGameUIRoot").GetComponent().activeHeight; float ratio = activeHeight / screenHeight; resultScale.x = (screenWidth / 2) * ratio; resultScale.y = (screenHeight / 2) * ratio; return resultScale; }
댓글 없음 :
댓글 쓰기