- Home /
Question by
MicahDuck · Jan 24, 2018 at 01:23 AM ·
ui3drecttransformworldtoscreenpoint
WorldToScreenPoint UI element showing up twice
Hello there, I'm currently working on indicators to show the location of teammates in a game i'm creating(3D). I'm using WorldToScreenPoint and it works fine, but the problem is that the UI elements also show up in the opposite direction. So if i'm looking at a teammate and do a 180 I will see the element again. Any information on how to prevent or fix this would be great, Thanks! Here is the code itself.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIFollowItem: MonoBehaviour {
public RectTransform canvasRectT;
public GameObject uiObject;
public RectTransform uiItem;
public Transform objectToFollow;
public Camera cam;
public void Start()
{
GameObject pointer = Instantiate(uiObject);
pointer.transform.SetParent(canvasRectT);
uiItem = pointer.GetComponent<RectTransform>();
uiItem.localScale = new Vector3(1, 1, 1);
}
void LateUpdate()
{
if(objectToFollow != null)
{
uiItem.transform.position = cam.WorldToScreenPoint(objectToFollow.transform.position);
}
}
}
Comment
Best Answer
Answer by MicahDuck · Jan 27, 2018 at 03:06 AM
I ended up just checking the z to see if it was in front or behind me
Your answer
![](https://koobas.hobune.stream/wayback/20220612151154im_/https://answers.unity.com/themes/thub/images/avi.jpg)