Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

NGUI positioning over NPC

$
0
0
Hi. As the question says, I'm trying to position a NGUI object over a NPC. This is the code that I'm using to do it: private GameObject CreateOrderBalloon() { GameObject balloon = GameObject.Instantiate( _orderPrefab ) as GameObject; balloon.transform.parent = NGUITools.FindCameraForLayer( LayerMask.NameToLayer( "GUI2D" ) ).transform.parent; balloon.GetComponent().SetOrder( _currentOrder ); Vector3 gui2dPos = Camera.main.WorldToScreenPoint( transform.position ); Debug.Log(transform.position); gui2dPos.x -= (Screen.width / 2.0f); gui2dPos.y -= (Screen.height / 2.0f); gui2dPos.z = 0; Debug.Log(gui2dPos); balloon.transform.position = Camera.main.ScreenToWorldPoint(gui2dPos); balloon.transform.localRotation = Quaternion.identity; balloon.transform.localScale = Vector3.one; return balloon; } However, no matter what's my NPC position, the balloon is always instantiated at Vector3.zero. For example, this is what the Debug.Log prints: > Debug.Log(transform.position): -4.5, 0.0, 0.0>> Debug.Log(gui2dPos): -133.4, 0.0, 0.0 And that is the position of the instantiated NGUI balloon: > P: 0, 0, 0>> R: 0, 0, 0>> S: 1, 1, 1 Here is the whole scene: ![alt text][1] As can be seen, the ballon is in the middle of the scene, not in the same position of the NPC at the stall. I don't know what is wrong. I've been stucked with this problem for 2 days. Thank you. [1]: /storage/temp/38166-captura+de+tela+2015-01-04+às+17.28.21.png

Viewing all articles
Browse latest Browse all 536

Trending Articles