Hello, everybody! Now i have another obstacle. I wonder how to make a health gui for each of my AI. And that health gui follows particular AI wherever it goes!
Thanks in advance!
1 Answer
1Yup thats quite easy actually:
We have these wonderfull functions to convert from screen, world and viewpoint.
Like this one:
http://unity3d.com/support/documentation/ScriptReference/Camera.ViewportToScreenPoint.html
You supply the functions with 3D coords and gets a 2D coord which you can use to place your GUI object.
The GUI object can be anything you like, you just get the X/Y screencoord and the rest is up to you.
Can you handle it from here?
No !!! I have looked at the link above. But it didn't give much information. Can you tell me a bit more detail? ^^
– henry96Ok how about this- the line Vector2 drawGUIHere = Camera.main.WorldToScreenPoint(enemyPosition); this gives you everything you need! As long as you know how to use the GUI and GUILayout? EDIT: Oh wait there was one other thing- the y value in that is inverted- you need to transform it like properY = Screen.height - originalY; Seriously, though, all this information is like 3 clicks away from that link BerggreenDK sent you!
– syclamothHmmmmm....... I have tried that, but I think I still didn't get it right. I try to print the Camera.main.WorldToScreenPoint(enemyPosition); but the number of the x is way too much (237751). I don't understand much about this thing. :(
– henry96Oh!!! Wrong typing! I tried the ViewportToscreenPoint not the world!!! Sorry about that!!! Can you guide me briefly to achieve this process? :)
– henry96
So something like a health bar displayed over the AI?
– Eli-Davisyeah !!! ^^
– henry96