using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AirportILS : MonoBehaviour
{
[Range(1f, 60f)] public float ILSangle = 20f;
public float ILSrange = 10f;
[Tooltip("Direction of the ILS in degrees (0 = up, 90 = right)")]
public float direction = 0f;
public PolygonCollider2D ILSbeam;
public Transform Emitter;
void Start()
{
ILSbeam = GetComponent<PolygonCollider2D>();
GenerateBeam();
}
void GenerateBeam()
{
float halfAngleRad = Mathf.Deg2Rad * (ILSangle / 2f);
// Local triangle points before rotation
Vector2 pointA = Vector2.zero;
Vector2 pointB = new Vector2(Mathf.Tan(halfAngleRad) * ILSrange, ILSrange);
Vector2 pointC = new Vector2(-Mathf.Tan(halfAngleRad) * ILSrange, ILSrange);
// Rotate points around pointA (origin)
pointB = Quaternion.Euler(0f, 0f, direction) * pointB;
pointC = Quaternion.Euler(0f, 0f, direction) * pointC;
ILSbeam.pathCount = 1;
ILSbeam.SetPath(0, new Vector2[] { pointA, pointB, pointC });
ILSbeam.isTrigger = true;
}