Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: danthat on November 10, 2012, 08:46:50 AM
-
I'd like to use nGUI to point the player towards any off-screen enemies. So if an enemy is 400 metres to the right of the player, you'd get a little enemy icon pointing in his general direction. Terrible mockup screenshot example:
(http://i.imgur.com/s8dde.png)
I can't quite get my head around the best way to do it using nGUI. Should I be using HUDtext for this, or is it all possible with nGUI vanilla?
Problem is, I'm unsure how to generate widgets at runtime with nGUI. I can grab all Colliders in range of the player with Physics.OverlapSphere and test Renderer.IsVisible... but I then need a way of generating widgets and clamping the labels to screen extremities.
Ideally I guess all Enemy objects would just have a child widget that I send to my Panel if !Renderer.IsVisible, but that doesn't seem workable because I think widgets require a Panel parent? Is that right?
Any suggestions gratefully received. I thought this sort of thing would be widely discussed, but I've been Googling around the subject for a couple of hours and haven't found a decent solution.
-
HUDText won't help you here. Knowing the position of your enemy, you can simply (enemyPos - yourPos) and normalize it to get the direction. This gives you a value of XY in -1 to 1 range. Multiply X by half of screen width, and Y by half of screen height, and you get your position on the screen's edge where you will place your target indicator.
-
Ah, ok. Thanks. And what about generating suitable widgets at runtime? Is there a sensible method behind that?
-
I recommend creating a prefab out of what a single indicator should be like, then simply instantiating it using NGUITools.AddChild.