I want a label to be visible for two cameras, but I don’t want it to be drawn twice. How can I do that? I have two players and each of them takes the Camera.main to his view (lets say third person view).
With the following script I can draw a label for each “Player”.
I have a script “DrawLabel” that looks like this:
void OnGUI(){
GameObject [] gobjects = GameObject.FindGameObjectsWithTag ("Player");
foreach (GameObject playerObj in gobjects) {
Vector3 screenposition = Camera.main.WorldToScreenPoint(playerObj.transform.position);
GUI.Label(new Rect(screenposition.x, Screen.height - (screenposition.y), 50, 50), playerObj.name);
}
}
When this script is attached to one player it draws the text only for him. The other player does not see the labels. But when attached to the other player, each player sees the text twice.
How can I fix that?