Target Indicators Display On Two Sides

Ok, so I didn’t really know how to word that question. Here is what’s happening. I am using a very crude, but simple way to add target indicators to the game I’m working on. The problem is, while they display on the enemies, they are also displaying on the OPPOSITE side. Here are some images:

Here’s facing front

And here’s facing back

And here is the oh so complicated code:

using UnityEngine;
using System.Collections;

public class TargetIndicator : MonoBehaviour {
	public Transform target;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		Vector3 wantedPos = Camera.main.WorldToViewportPoint(target.position);
		transform.position = wantedPos;
	}
}

I can’t seem to figure out why there are two sets of indicators. Oh also, I should mention the GUI texture is a child of each enemy with the code displayed above attached to the Texture. It feels very crude and slammed together, but it’s really simple and works fro what I need, if I could keep it that way, then it’d be great.

The theory that I have as to why it’s doing this, is because the script is attached to the texture, which is attached to the enemy. Is it possible that the enemy is displaying the same texture, just with the coordinates inverted?

Anyhow, both sets of indicators move, and as the actual enemies pass by me, the other set of indicators passes by as well, heading in the opposite direction of the enemies. It’s pretty strange.

Any and all help is deeply appreciated.

If I understand you correctly, this will fix your issue:

void Update () {
   Vector3 wantedPos = Camera.main.WorldToViewportPoint(target.position);
   transform.position = wantedPos;
   renderer.enabled = wantedPosition.z > 0.0f;
}

That is, when doing a WorldToViewportPoint() the returned ‘z’ value indicates the distance in front of the camera. Negative values are behind the camera, and positive values are in front of the camera. So this code turns off the renderer if the the position is behind the camera.