Offscreen target indicator- how to do it???


I wrote a script.

When an object (ENEMY) is within the player’s range, the arrow points to it.

However, I would like the arrow to be just the edge of the camera.

And when the object appears in the camera, it should disappear.

How to do it?

PS. the script is attached to the PLAYER object.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetIndicator : MonoBehaviour {
	public Transform Target;
	public float HideDistance;
	// Use this for initialization
	void Start () {


	// Update is called once per frame
	void Update () {
		var dir = Target.position - transform.position;
		if (dir.magnitude < HideDistance) {
			SetChildrenActive (false);
			SetChildrenActive (true);
			var angle = Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg;
			transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

	void SetChildrenActive (bool value){

		foreach (Transform child in transform)

Many ways to do this. One could be comparing camera position + size x/y and enemy’s position to know if it’s out of view, you can then return a value to know if the enemy is on top/right/bottom/left side and update arrow’s position on x or y…
Not sure if it has any impact but it might be cleaner to check if your child is not active before activating it on each frame even if I have no idea what is your player’s children…