Forum rules - please read before posting.

Getting Screen Position of Menu

edited July 2017 in Technical Q&A
Hello,

I'm trying to make an animation, where the player picks up an item, and then the item has an animation into a menu. The problem is that I can't seem to find the screen position of this menu item, it always seems to have a large offset relative to the screen. I've digged into the code as well, and couldn't find much info.

I've tried to use some of the Menu's properties to get this position, but didn't expect some of the results:
- manualPosition - returns an offset from the screen
- canvas - returns null
- rectTransform - returns null
- GetRect() - returns  (0, 0)
- Centre - returns an offset even farther than manualPosition

Is there a way to get the position of a menu (with 'Aligned' position), relative to the screen, so that I can get World Coordinates based on that?

Thank you in advance.

Comments

  • Assuming you're using Adventure Creator as your Menu's Source, the Canvas and RectTransform fields will always return null - as they're linked to Unity UI (see their descriptions in the scripting guide).

    GetRect should indeed return the boundary of the Menu - lets see what your Menu's properties look like in the Menu Manager.

    You also have the option of reading GetSlotCentre, should you be able to work with the position of an element.
  • edited July 2017
    GetSlotCentre(), that was it!
    I just needed to convert that screen space into World Space, but I also had to do this: 

    centre.y = Screen.height - centre.y;

    It seems that Rects and Screen spaces have different starting points. But apart from that, that's the property I needed.

    I also forced myself to read a bit about Canvas, RectTransform and Unity UI on AC, now I have a better understanding on the underlaying stuff that's happening.

    Thank you so much!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.