Author Topic: Element position in World  (Read 1430 times)


  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Element position in World
« on: August 28, 2016, 03:25:06 PM »
Hello. I have tried searching for a solution for quite some time now, but people seem to want to place ngui elements over gameobjects instead of the opposite.
I want to on a click generate a GameObject and move it towards a sprite (or a label), but i cant seem to be able to get world position of an ngui element

I have tried Camera.main.ViewportToWorldPoint(gui.transform.position); which seems to point me in the right direction atleast (it overpasses the target tho depending on the screen width) Also have attempted some stuff like UIRootCamera.ViewportToWorldPoint, havent had much luck
ScreenToWorldPoint gives me a point in the lower right corner of the screen and i have also tried some other variants that end up pointing at about (1.5,0.5,100) which is actually gui.transform.position? (gui is the label im trying to target)

This is all very confusing to me and i am definitely doing something wrong so how do i get world point of and ngui element? Or maybe on other terms place a gameobject over (under) a ui element.


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Element position in World
« Reply #1 on: August 30, 2016, 09:18:18 PM »
The problem with placing a 3D object using a 2D coordinate is that you're missing depth. Where's the Z going to come from if you only have X and Y to work with? You would need to do a raycast into the scene at XY in order to figure out a 3D point first.