3DTD/Assets/Scripts/Tower/Tower.cs

37 lines
1.2 KiB
C#

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<HealthComponent>();
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);
}
}