Trying to figure this out and just feel lost. I think I want to use the IsVisible for the UIFollowTarget to get the other player's name to show/not show based on distance from the player... but just cannot figure out where to start. Ideally would love to fade it in as you get closer, but fine with just doing the above.
I am guessing I need to set the x/y but not sure where to start with it.
Here is what I have tried so far... but I think the distance / position stuff is completely off
Vector3 gamePosition = gameCamera.WorldToViewportPoint(target.position);
Vector3 uiPosition = uiCamera.WorldToViewportPoint(mTrans.localPosition);
// Determine the visibility and the target alpha
bool isVisible = (gameCamera.isOrthoGraphic || gamePosition.z > 0f) && (!disableIfInvisible || (gamePosition.x > 0f && gamePosition.x < 1f && gamePosition.y > 0f && gamePosition.y < 1f));
//Make disappear if too far away
if (isVisible) {
var distance = Math.Sqrt(Math.Pow((uiPosition.x - gamePosition.x), 2) + Math.Pow((uiPosition.y - gamePosition.y), 2));
Debug.Log(distance);
if (distance > 70) {
isVisible = false;
}
}
Any help would be much appreciated. Thanks!