- Home /
Question by
CaptainCarl · Feb 09, 2014 at 03:10 PM ·
cameraguigameobjectgui-text
"Press [e] to open" on stationary object when onTrigger
I want a text to be shown on a gameobject I'm triggering but leave the text on the stationary object.
I now have a GUItext which is being set on a X and Y position via the WorldToScreenPoint. But this moves along with my camera, and I want it to be on the top right of the gameObject. How would I manage this?
public function setText(text, x, y) {
if (!this.talkTriggerIsOpen) {
this.talkTriggerIsOpen = true;
var go : GameObject = new GameObject("TriggerText");
go.AddComponent("GUIText");
go.guiText.color = new Color(1.0f, 1.0f, 1.0f);
go.guiText.text = text;
var camera = GameObject.Find("MainCamera").camera;
var screenPos : Vector3 = camera.WorldToScreenPoint (transform.position);
go.guiText.pixelOffset = new Vector2(screenPos.x, screenPos.y);
go.guiText.fontSize = 14;
}
}
Comment
Your answer
Follow this Question
Related Questions
GUI Window on GameObject location? 1 Answer
Is it possible to link a UI element to a gameobject? 1 Answer
Keep GameObject on a corner of the screen 1 Answer
GUI controlling other game objects 0 Answers
Render GameObjects over GUI.Layer 1 Answer