Well, the problem is quite well-known, but wherever I am, no one anywhere has done this on the UI. Well, or I bad surf WWW. In general, this is what we want:

Approximate implementation of the task. .

In my case, the black rectangle will be Canvas with the display parameter Screen Space - Overlay , the indicators UI Image and the target (enemies) GameObject .

Below I will leave a way to solve this problem, and explain why it does not suit me.

I need this system, but it works on UI.

PS: Maybe the question will be stupid, but at my age we still do not even need to know the definition of radians in the education system.

    1 answer 1

    Well, well, this script needs to be put on the GameObject arrows, which will indicate the target.

    Well and actually Sprite Render with an arrow which will be displayed to deliver do not forget.

     using UnityEngine; public class OffScreenArrow : MonoBehaviourTFD { //Цель, на которую будет показывать стрелка. public Transform target; void LateUpdate() { //Если цель существует... if (target) { Vector3 v_diff = (target.position - GOs.Player.transform.position); float atan2 = Mathf.Atan2(v_diff.y, v_diff.x) * Mathf.Rad2Deg; //В моём случае спрайт стрелки повёрнут вверх, так что я отнял 90 градусов. transform.rotation = Quaternion.Euler(0f, 0f, atan2 - 90); //Вычесляем нужное значение... transform.position = Vector3.MoveTowards(transform.position, target.transform.position, 1000); //и подганяем его под размеры экрана. Vector3 pos = Camera.main.WorldToViewportPoint(transform.position); pos.x = Mathf.Clamp01(pos.x); pos.y = Mathf.Clamp01(pos.y); transform.position = Camera.main.ViewportToWorldPoint(pos); } } } 

    And although the script is a bit damp, it performs its main function quite well.

    But then a serious drawback emerges: UI Image with my canvas will always be higher priority than Sprite Render , which means that the interface will block this arrow, which is not an option at all. It is also not very convenient to work with a bunch of such arrows, because they will overlap each other and it will be impossible to sort them out like a UI Image . Therefore, at least this option is partially suitable, but it does not suit me.