LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/DigitalRuby/ThunderAndLightning/LightningBeamSpellScript.cs

73 lines
1.8 KiB
C#
Raw Normal View History

2023-12-22 22:51:17 +00:00
using System;
using UnityEngine;
namespace DigitalRuby.ThunderAndLightning
{
public class LightningBeamSpellScript : LightningSpellScript
{
[Header("Beam")]
[Tooltip("The lightning path script creating the beam of lightning")]
public LightningBoltPathScriptBase LightningPathScript;
[Tooltip("Give the end point some randomization")]
public float EndPointRandomization = 1.5f;
[HideInInspector]
public Action<RaycastHit> CollisionCallback;
private void CheckCollision()
{
if (Physics.Raycast(SpellStart.transform.position, Direction, out var hitInfo, MaxDistance, CollisionMask))
{
SpellEnd.transform.position = hitInfo.point;
SpellEnd.transform.position += UnityEngine.Random.insideUnitSphere * EndPointRandomization;
PlayCollisionSound(SpellEnd.transform.position);
if (CollisionParticleSystem != null)
{
CollisionParticleSystem.transform.position = hitInfo.point;
CollisionParticleSystem.Play();
}
ApplyCollisionForce(hitInfo.point);
if (CollisionCallback != null)
{
CollisionCallback(hitInfo);
}
}
else
{
if (CollisionParticleSystem != null)
{
CollisionParticleSystem.Stop();
}
SpellEnd.transform.position = SpellStart.transform.position + Direction * MaxDistance;
SpellEnd.transform.position += UnityEngine.Random.insideUnitSphere * EndPointRandomization;
}
}
protected override void Start()
{
base.Start();
LightningPathScript.ManualMode = true;
}
protected override void LateUpdate()
{
base.LateUpdate();
if (base.Casting)
{
CheckCollision();
}
}
protected override void OnCastSpell()
{
LightningPathScript.ManualMode = false;
}
protected override void OnStopSpell()
{
LightningPathScript.ManualMode = true;
}
}
}