title: Unity offscreen target indicator-how to show the way to an object with a specific tag?
body: <p>UNITY 2D C#</p>
  
  <p>Hi everyone.
  I have a script that allows the arrow to show where the point is .</p>
  
  <p>My problem:</p>
  
  <p>1) I would like the arrow to show the way to a point with a specific tag or name.</p>
  
  <p>How to do it?</p>
  
  <p>Because now, shows the way to the point (-50,0).</p>
  
  <p>Could anyone help me transform the script?</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using CodeMonkey.Utils;
  
  
  public class Window_QuestPointer : MonoBehaviour {
  
  [SerializeField] private Camera uiCamera;
  
  
  
  private Vector3 targetPosition;
  private RectTransform pointerRectTransform;
  
  private void Awake ()
  {
      targetPosition = new Vector3 (-50, 0);
      pointerRectTransform = transform.Find ("Pointer").GetComponent&lt;RectTransform&gt; ();
  }
  private void Update (){
      Vector3 toPosition = targetPosition;
      Vector3 fromPosition = Camera.main.transform.position;
      fromPosition.z = 0f;
      Vector3 dir = (toPosition - fromPosition).normalized;
      float angle = UtilsClass.GetAngleFromVectorFloat(dir);
      pointerRectTransform.localEulerAngles = new Vector3 (0, 0, angle);
  
      float borderSize = 40f;
  
      Vector3 targetPositionScreenPoint = Camera.main.WorldToScreenPoint (targetPosition);
      bool isOffscreen = targetPositionScreenPoint.x &lt;= borderSize || targetPositionScreenPoint.x &gt;= Screen.width - borderSize || targetPositionScreenPoint.y &lt;= borderSize || targetPositionScreenPoint.y &gt;= Screen.height - borderSize;
      Debug.Log (isOffscreen + " " + targetPositionScreenPoint);
  
      if(isOffscreen){
          Vector3 cappedTargetScreenPosition = targetPositionScreenPoint;
          cappedTargetScreenPosition.x = Mathf.Clamp (cappedTargetScreenPosition.x, borderSize, Screen.width - borderSize);
          cappedTargetScreenPosition.y = Mathf.Clamp (cappedTargetScreenPosition.y, borderSize, Screen.height - borderSize);
  
          Vector3 pointerWorldPosition = uiCamera.ScreenToWorldPoint (cappedTargetScreenPosition);
          pointerRectTransform.position = pointerWorldPosition;
          pointerRectTransform.localPosition = new Vector3 (pointerRectTransform.localPosition.x, pointerRectTransform.localPosition.y, 0f);
  
      }
      else{
          Vector3 pointerWorldPosition = uiCamera.ScreenToWorldPoint (targetPositionScreenPoint);
          pointerRectTransform.position = pointerWorldPosition;
          pointerRectTransform.localPosition = new Vector3 (pointerRectTransform.localPosition.x, pointerRectTransform.localPosition.y, 0f);
  
  }
  </code></pre>
  
  <p>}
  }</p>