magic powers refactor WIP
This commit is contained in:
52
Assets/Scripts/Characters/Skills/ScanSpell.cs
Normal file
52
Assets/Scripts/Characters/Skills/ScanSpell.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
|
||||
namespace Beyond
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Magic/Spells/Scan")]
|
||||
public class ScanSpell : SpellDefinition
|
||||
{
|
||||
public GameObject effectPrefab;
|
||||
public float maxRange = 50f;
|
||||
public float scanDuration = 2f; // time for wave to travel
|
||||
public float startDelay = 0.6f;
|
||||
|
||||
public override void Cast(MagicAttacks caster, Transform target)
|
||||
{
|
||||
caster.StartCoroutine(CastRoutine(caster));
|
||||
}
|
||||
|
||||
private IEnumerator CastRoutine(MagicAttacks caster)
|
||||
{
|
||||
yield return new WaitForSeconds(startDelay);
|
||||
// Instantiate visual
|
||||
GameObject instance = Instantiate(effectPrefab, caster.transform.position, Quaternion.identity);
|
||||
VisualEffect vfx = instance.GetComponent<VisualEffect>();
|
||||
if (vfx) vfx.Play();
|
||||
|
||||
// Shader Logic
|
||||
float speed = maxRange / scanDuration;
|
||||
float timer = 0f;
|
||||
|
||||
while (timer < scanDuration)
|
||||
{
|
||||
Shader.SetGlobalFloat("_WaveTime", speed * timer);
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
Shader.SetGlobalFloat("_WaveTime", 0f);
|
||||
|
||||
// Detection Logic
|
||||
int mask = 1 << LayerMask.NameToLayer("Triggers") | 1 << LayerMask.NameToLayer("HiddenObject");
|
||||
var colliders = Physics.OverlapSphere(caster.transform.position, maxRange, mask);
|
||||
foreach (var c in colliders)
|
||||
{
|
||||
var h = c.gameObject.GetComponent<IScannable>();
|
||||
if (h != null) h.OnScanned();
|
||||
}
|
||||
|
||||
Destroy(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user