quantum-space-buddies/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs

35 lines
1.2 KiB
C#
Raw Normal View History

2022-03-11 13:40:52 +00:00
using QSB.WorldSync;
2022-03-11 03:17:06 +00:00
using UnityEngine;
2021-11-11 05:13:49 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.MeteorSync.WorldObjects;
public class QSBMeteorLauncher : WorldObject<MeteorLauncher>
2021-11-11 05:13:49 +00:00
{
2022-03-03 03:46:33 +00:00
public void PreLaunchMeteor()
{
2022-03-11 03:17:06 +00:00
foreach (var launchParticle in AttachedObject._launchParticles)
2021-11-11 05:13:49 +00:00
{
2022-03-11 03:17:06 +00:00
launchParticle.Play();
2021-11-11 10:08:03 +00:00
}
2022-03-03 03:46:33 +00:00
}
2021-11-11 10:08:03 +00:00
public void LaunchMeteor(MeteorController meteor, float launchSpeed)
2022-03-03 03:46:33 +00:00
{
meteor.Initialize(AttachedObject.transform, AttachedObject._detectableField, AttachedObject._detectableFluid);
2022-03-11 03:17:06 +00:00
var linearVelocity = AttachedObject._parentBody.GetPointVelocity(AttachedObject.transform.position) + AttachedObject.transform.TransformDirection(AttachedObject._launchDirection) * launchSpeed;
var angularVelocity = AttachedObject.transform.forward * 2f;
meteor.Launch(null, AttachedObject.transform.position, AttachedObject.transform.rotation, linearVelocity, angularVelocity);
2022-03-11 03:17:06 +00:00
if (AttachedObject._audioSector.ContainsOccupant(DynamicOccupant.Player))
{
AttachedObject._launchSource.pitch = Random.Range(0.4f, 0.6f);
AttachedObject._launchSource.PlayOneShot(AudioType.BH_MeteorLaunch);
}
2022-03-11 03:17:06 +00:00
foreach (var launchParticle in AttachedObject._launchParticles)
2022-03-03 03:46:33 +00:00
{
2022-03-11 03:17:06 +00:00
launchParticle.Stop();
2021-11-11 05:13:49 +00:00
}
}
2022-03-11 03:17:06 +00:00
}