No position variable for GUIText()?

public class OverHeadEffects: MonoBehaviour {

    GUIText text;

    public OverHeadEffects(Vector3 pos)
    {
        this.gameObject.transform.position = new Vector3(pos.x, pos.y+10f, pos.z);
    }
	



    public void setTextColor(string text, string color = "#000000"){
        this.text = new GUIText();
        this.text.richText = true;
        this.text.text = "<color=\"" + color + "\">" + text + "</color>";
    }
    public void setText(string text){
        this.text = new GUIText();
        this.text.text = text;
    }
    public string getText() { return this.text.text; }
}

…I’m guessing there’s something I’m missing about the way things interact in Unity. Basically, what I’m trying to make is a class which, when initialized by the character object, creates itself slightly above the character/enemies, the prints out a text string (in this case, it’s supposed to appear to show damage taken/dealt). However, GuiText has no transform variable, so I guess I’m a little confused. Do I need to attach it to an existing GameObject as a variable? How would I best do this?

GUIText does have a transform. You can access it by:

text.gameObject.transform.position = new Vector3(0.5, 0.5, 0.0);

But there is an issue with respect to placing GUIText adjacent to a game object. GUIText lives in Screen space. Most game objects live in World space. Screen coordinates start at (0,0) in the lower left of the screen and go to (1,1) in the upper right of the screen. In order to make the conversion you can use [Camera.WorldToScreenPoint()][1]. So you would do something like:

Vector3 v3ScreenPos = Camera.main.WorldToScreenPoint(v3WorldPosition);
text.gameObject.transform.position = v3ScreenPos;

I would not use Gui-Text as they can only really function very well inside of a GUI Texture (Atlas). Try using 3D Text it is the same as a GUI text, but moveable.