Hey there, I am using GUI.Label to indicate onscreen where asteroid fields are in the world.
The code I have works great, except for one thing. There are duplicate labels on screen, specifically two for each asteroid field. One label is in the correct spot, and one always seems to be onscreen where there is actually no asteroid field there. I figure it has something to do with 3D space and some asteroid fields not being onscreen when the text is made, but I’m not positive.
public class AsteroidTextHandler : MonoBehaviour {
public string text;
//private GUIStyle style = new GUIStyle();
private void OnGUI()
{
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
Vector2 tSize = GUI.skin.label.CalcSize(new GUIContent(text));
//style.fontSize = 12;
GUI.contentColor = Color.white;
GUI.Label(new Rect(pos.x, Screen.height - pos.y, tSize.x, tSize.y), text);
}
}
The text is passed through in my AsteroidHandler class and this script is a component of the asteroid field itself.