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.