Compiler error, not sure what to do different

I’m trying to learn the basics of making a game in Unity, and right now I’m working on implementing a simple A.I., one piece at a time. I want the enemy’s health, which is kept in a variable(of course), to be displayed above the enemy object. Here is the code I used to do this:

//Inspector Variables
var enemyHealth : float = 100;
var enemyMaxHealth : float = 100;
var target : Transform;

function OnGUI() {
var screenPos : Vector3 = camera.WorldToScreenPoint(target.position);
GUI.Label(Rect(screenPos+10,screenPos+10,screenPos+100,screenPos+200), enemyHealth);

The compiler error that comes up is where I’m adding screenPos + 10, because screenPos is a Vector3 and 10 is an integer(as you all know, I’m sure lol). Basically with the GUI.Label code I was attempting to draw the amount of health above the enemy object.

  1. What can I do to achieve this, and get rid of the compiler errors? I’m stumped.
  2. A somewhat separate question, but how would I draw the health/max health, like this: current enemy health = 80, max health = 100…“80 / 100”

Thanks for your help and time!

You need to extract the different parameters to use, i.e X for X position, Y for Y position (Z is the distance from the camera to the world point). Try :

GUI.Label( Rect( screenPos.x + 10, screenPos.y + 10, 100, 200 ), enemyHealth.ToString() );

I also changed the values in your Rect, see the docs and consider this :

Rect( startPosition.x, startPosition.y,  textureToDisplay.width, textureToDisplay.height)

screenPos+100,screenPos+200 will give you a massive Label area, it’s not so bad with GUI.Label but what if you are doing GUI.Box ?

for the second part of your question, check my answer here : How to do a fractional percentage - Questions & Answers - Unity Discussions