- Home /
NGUI doesn't work when camera is moving, but is fine when camera is stationary
Hi there
I'm developing the control system for a platformer and am using NGUI. Everything works correctly until I enable my camera to follow the character. That is to say, when the camera is static all the NGUI widgets etc all react as they should but when the camera is moving, buttons don't pick up every click and the UIDragObject I'm using as a joystick snaps to the side of the clipping bounds of it's panel.
Again, this all works fine if the camera doesn't move.
Each NGUI object has a UIAnchor set to use the camera and the camera has a UICamera script on it.
Do you have any ideas what the problem could be and/or how to solve it?
Answer by vexe · Oct 02, 2013 at 11:23 PM
You're using UI camera as your normal, platform camera, you're moving it, making it follow the player, etc.
Now:
-If your panel isn't a child of your UICamera
, then when you move it, make it follow the player, etc your panel and widgets will go out of the camera's range, so it won't detect them.
-else if it is a child to your UICamera
, then moving the camera around should also move the whole UI underneath the camera (the panel and the widgets) - You didn't mention that, so I guess that's not the case here.
Anyway, make sure you have a standard UI hierarchy, like:
Root
Camera
Anchor
Panel
And then, use a separate normal (doesn't have a UICamera
script) camera for your platformer purposes, move that around, follow the player, etc and leave your UICamera
intact.
PS: There's a 'Debug' checkbox in UICamera
, tick it, it gives you feedback on what collider the camera's ray is hitting, very helpful.
Let me know how it goes.
Thanks. Yeah the issue was from not having my UI camera as a separate camera from the player camera.