using UnityEngine; using UnityEngine.Assertions; public abstract class Tower : MonoBehaviour { public bool towerSelected { get; set; } = true; [SerializeField] protected EditableArc horizontalArc; [SerializeField] protected EditableArc verticalArc; protected HealthComponent healthComp; // Getters public Vector2 HorizontalRotationMinMax => horizontalArc.RotationMinMax; public Vector2 VerticalRotationMinMax => verticalArc.RotationMinMax; public float HorizontalRotation => horizontalArc.Value; public float VerticalRotation => verticalArc.Value; protected virtual void Awake() { healthComp = GetComponent(); Assert.IsNotNull(healthComp); horizontalArc.Value.AddListener(SnapVerticalToHorizontal); } private void SnapVerticalToHorizontal(float horizontalAngle) { verticalArc.transform.rotation = Quaternion.Euler(verticalArc.transform.rotation.eulerAngles.x, horizontalAngle, verticalArc.transform.rotation.eulerAngles.z); } protected virtual void OnDestroy() { horizontalArc.Value.RemoveListener(SnapVerticalToHorizontal); } }