//Converting to viewport point because it's easier to find point on the edge of the screen
var worldToViewportPoint = _gameCamera.WorldToViewportPoint(Target.position);
//Convert player position to screen point (this is constant because player is always centered, it is linked to game camera)
var playerWorldToScreenPoint = _gameCamera.WorldToScreenPoint(GameController.Instance.Player.CharacterTransform.position);
//Clamp the target position to edge of the screen (take GetPixelSizeAdjustment into account since i am not using pixel perfect)
var screenPosClamped
= new Vector3
(Mathf
.Clamp(worldToViewportPoint
.x, 0f, 1f
),Mathf
.Clamp(worldToViewportPoint
.y, 0f, 1f
),
0); var position
= new Vector3
((screenPosClamped
.x * Screen
.width - HalfScreenWidth
) * UIRoot
.GetPixelSizeAdjustment(_indicator
.gameObject),
(screenPosClamped.y * Screen.height - HalfScreenHeight) * UIRoot.GetPixelSizeAdjustment(_indicator.gameObject), 0);
//This gives me for one point something like this: (427.0, 191.6, 8.7) (-455.1, 360.0, 0.0)
//So I suspect this is something that is causing trouble
Debug.Log(playerWorldToScreenPoint.ToString() + " " + position.ToString());
//Set indicator prefab position at the edge of the screen (THIS IS WORKING CORRECTLY
_indicator.localPosition = position;