Aetheria/Assets/Scripts/Gameplay/ShieldManager.cs

42 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using UnityEngine;
public class ShieldManager : MonoBehaviour
{
public Prototype ShieldPrototype;
public float CollisionHitDuration = 3;
2026-06-21 09:37:54 +01:00
public float LootInteractionCooldown = 0.25f;
public float ShieldCollisionCooldown = 0.1f;
public Entity Entity { get; set; }
2026-06-21 09:37:54 +01:00
private bool IsShieldActive()
{
2026-06-21 09:37:54 +01:00
return Entity?.Shield != null && Entity.Shield.Item.Active.Value;
}
private Bounds ShieldBounds()
{
var renderers = GetComponentsInChildren<Renderer>();
if (renderers.Length == 0)
return new Bounds(transform.position, Vector3.one);
var bounds = renderers[0].bounds;
for (var i = 1; i < renderers.Length; i++)
bounds.Encapsulate(renderers[i].bounds);
2026-06-21 09:37:54 +01:00
return bounds;
}
2026-06-21 09:37:54 +01:00
private static float ShieldPlanarRadius(Bounds bounds)
{
2026-06-21 09:37:54 +01:00
return Mathf.Max(bounds.extents.x, bounds.extents.z, 0.001f);
}
public void ShowHit(Vector3 point, float duration)
{
var shield = ShieldPrototype.Instantiate<ShieldAnimation>();
2026-06-21 09:37:54 +01:00
shield.Direction = shield.transform.InverseTransformPoint(point).normalized;
shield.Duration = duration;
}
}