Drawing Player Indicator Around Teammates

Hello all,

I’m trying to find a good way to see my teammates through walls by displaying an indicator around them.
I’m thinking this belongs on each player’s HUD, and then I can loop through all other players in an update function, and get their coordinates, translate to local viewport coords, and display something there.

I might be along the right track, but implementing it is another story (rather new to Unity). Any advice, or working examples would be much appreciated :slight_smile:

Edit: Thinking now that I would need to instantiate some sort of object at the local viewport coordinates for each player on my team. Still any examples would be appreciated!

Edit 2: What I’m doing now is in an OnGUI() method:

	public void OnGUI()
	{
		if(Game.IsTeamBased)
		{
			foreach(var player in Game.PlayerScripts)
			{
				if(player != this  player.TeamNum == this.TeamNum)
				{
					var playerCoords = player.transform.position;
					var screenCords = mFPCamera.WorldToScreenPoint(playerCoords);
					GUI.Label(new Rect(screenCords.x, screenCords.y, 40, 20), player.Statistics.Name);
				}				
			}			
		}
	}

This has some problems though.

  1. The coordinates look to be wrong. Some text is statically just sitting still on screen.
  2. My game supports up to 4 player split screen, and I’m thinking the screen coordinates given back by each player’s FPCamera don’t account for this.

Wondering if I should go a GUI route or perhaps draw something around each player in the world instead, and just enable/disable it based on whether or not the player looking at them is a teammate? But if it’s not a GUI element, I’m not sure it could be oriented so it’s facing every player at the same time?

Also, if I get the GUI approach working, I can use that for name tags as well.