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

49 lines
1.1 KiB
C#
Raw Normal View History

2024-04-20 19:22:52 +02:00
using UnityEngine;
public class GravityTower : Tower
{
[SerializeField, Range(0.1f, 10f)]
private float radius = 1f;
[SerializeField]
private Transform orb;
[SerializeField]
private LayerMask affectedBodies;
[SerializeField]
private AnimationCurve distToAcceleration;
2024-04-20 22:42:06 +02:00
public override void TowerSelected(bool selected)
{
}
protected override void Awake()
{
base.Awake();
}
2024-04-20 19:22:52 +02:00
protected override void FixedUpdate()
{
Collider[] projectilesInRadius = Physics.OverlapSphere(orb.position, radius, affectedBodies);
foreach (var projectile in projectilesInRadius)
{
Rigidbody projectileBody = projectile.GetComponent<Rigidbody>();
Vector3 projToOrb = orb.position - projectile.transform.position;
float dist = projToOrb.magnitude;
projectileBody.AddForce(projToOrb.normalized * distToAcceleration.Evaluate(dist));
}
}
2024-04-20 22:42:06 +02:00
protected override void OnDestroy()
{
base.OnDestroy();
}
protected override void Update()
{
base.Update();
}
2024-04-20 19:22:52 +02:00
}