This reference from unity works perfectly; however, it only works when trying to detect the angle of a single game object. Is there some way to make this into an array, so that it detects whether or not any game objects are within a certain degrees? As of now, it only detects the angle of a single game object and ignores any others. C# only please, THANKS!!!
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform target;
void Update() {
Vector3 targetDir = target.position - transform.position;
Vector3 forward = transform.forward;
float angle = Vector3.Angle(targetDir, forward);
if (angle < 5.0F)
print("close");
}
}