Hello everyone ![]()
I am trying to make the green square follow the box’ position on my HUD.
I am using a world space canvas for the HUD and a script I found online to follow the target’s position on the UI. The green square is a UI image.
Here is the script. I can’t see any reason why it is so much offset.
using UnityEngine;
using UnityEngine.UI;
public class ReticleOverEnemy : MonoBehaviour
{
public RectTransform canvasRectT;
public RectTransform reticle;
public Transform objectToFollow;
public Camera _camera;
void Update()
{
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(_camera, objectToFollow.position);
reticle.anchoredPosition = screenPoint - canvasRectT.sizeDelta;
}
}
Thanks in advance everyone ![]()
