I would like to create a gui texture which “points”(i.e. is placed at) a physical 3d object. I read alot about this line of code:
Camera.mainCamera.WorldToScreenPoint(target.transform.position);
But when I implement it, it gives me strange values. At some stages it gives me something like 7500 for my x. The tiny game screen in the centre only displays a range of 0->0.9 for x and y, so any value above 1 is not renderable.
How can I implement WorldToScreenPoint correctly?
#pragma strict
public var objectiveIcon : GUITexture;
public var objectiveDescription : GUIText;
private var icon : GUITexture;
private var description : GUIText;
function Start ()
{
icon = Instantiate(objectiveIcon);
description = Instantiate(objectiveDescription);
}
function Update ()
{
icon.transform.position = Camera.mainCamera.WorldToScreenPoint (this.transform.position);
icon.transform.position.y = Screen.height - icon.transform.position.y;
description.transform.position = Camera.mainCamera.WorldToScreenPoint (this.transform.position);
description.transform.position.y = Screen.height - icon.transform.position.y;
Debug.Log(icon.transform.position.ToString());
Debug.Log(description.transform.position.ToString());
}
function OnDestroy ()
{
Destroy(icon);
Destroy(description);
}