Author Topic: UIAnchor positioning in the wrong place  (Read 2744 times)

roberto_sc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
UIAnchor positioning in the wrong place
« on: July 15, 2013, 07:53:01 PM »
Hello
I'm a beginner NGUI user trying to add a button at the top left of my screen.

There are two problems:

1 - I add a UI Root 2D using the UI Wizard and add a Button under a Panel using Widget Wizard. Afterwards, I add an UIAnchor script to the button, set the camera in the script and send it to the top left. It centres the button centre in the top left (first pixel) of the screen, so I end up seeing 1/4 of the button. Is this the expected behaviour? Do I have to use offsets?

2 - I already have a main camera in my game, which is isometric, so I don't want that camera the UI Wizard creates. I create a new UI Root but use "None" as Camera. Again, create a Button under the Panel, add UIAnchor, set it to use my camera and send to top left. The button goes out of the camera view. What am I doing wrong?

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: UIAnchor positioning in the wrong place
« Reply #1 on: July 15, 2013, 08:35:35 PM »
1. This is the intended behavior, and yes, you need to use offsets.
I usually create an empty GameObject for my button alignment, and then position my buttons beneath that. You could try fiddling with the offset values to bump it to the right slightly, but the button alignment gets skewed on different devices because of the changes in screen dimensions.

2. Did you add the UICamera component to your own camera? If you do, does it work? By the look through the code, UIPanel is looking for a UICamera, and although UIAnchor is just using a "Camera", it has the same construct as the UIPanel. Another thing to check: Is the layer of your button set to UI (or whatever your main camera is set to render)?

roberto_sc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: UIAnchor positioning in the wrong place
« Reply #2 on: July 15, 2013, 10:54:27 PM »
Thank you for your reply, OnlineCop.
Yes, my camera has a UICamera and it works: when I set the anchor to "Center", the buttons appears in the center of screen, and I can press it. That also answers your second question.

It seems that the panel is bigger than it should be. Shouldn't it be the size of my viewport?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAnchor positioning in the wrong place
« Reply #3 on: July 16, 2013, 10:33:01 AM »
Camera used for the UI needs to have an orthographic size of 1.

I recommend you keep the UI using a separate camera.