30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
using UnityEngine;
|
|
|
|
public class AbilityUser : MonoBehaviour
|
|
{
|
|
[Header("Refs")]
|
|
public ManaManager mana;
|
|
public HealthManager health;
|
|
public Transform castPoint; // where projectiles spawn
|
|
public Camera aimCamera; // for raycasts (optional)
|
|
|
|
void Reset()
|
|
{
|
|
aimCamera = Camera.main;
|
|
castPoint = transform;
|
|
}
|
|
|
|
// Helpers
|
|
public bool TrySpendMana(float amount) => !mana || mana.Spend(amount);
|
|
public void HealSelf(float amount) { if (health) health.Heal(amount); }
|
|
|
|
public bool RaycastAim(out RaycastHit hit, float maxDistance = 50f, LayerMask mask = default)
|
|
{
|
|
if (!aimCamera) { hit = default; return false; }
|
|
return Physics.Raycast(aimCamera.ScreenPointToRay(Input.mousePosition), out hit, maxDistance, mask);
|
|
}
|
|
|
|
public Vector3 Forward() => castPoint ? castPoint.forward : transform.forward;
|
|
public Vector3 Upward() => castPoint ? castPoint.up : transform.up;
|
|
public Vector3 CastPos() => castPoint ? castPoint.position : transform.position;
|
|
} |