Adds a 5 second cooldown to warp transmitters after using return pad

This commit is contained in:
Nick 2023-07-01 18:20:03 -04:00
parent c7ad912acf
commit f0f24b2777
2 changed files with 41 additions and 0 deletions

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.Props.TranslatorText;
using NewHorizons.Components;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.WarpPad;
using NewHorizons.Utility;
@ -137,6 +138,9 @@ namespace NewHorizons.Builder.Props
transmitter.GetComponent<BoxShape>().enabled = true;
// Prevents the transmitter from sending you straight back if you use the return function of the receiver #563
transmitterObject.AddComponent<NomaiWarpTransmitterCooldown>();
transmitterObject.SetActive(true);
}

View File

@ -0,0 +1,37 @@
using UnityEngine;
namespace NewHorizons.Components
{
public class NomaiWarpTransmitterCooldown : MonoBehaviour
{
private NomaiWarpTransmitter _transmitter;
private NomaiWarpReceiver _receiver;
private float _reenabledTime = 0f;
private bool _cooldownActive;
public void Start()
{
_transmitter = GetComponent<NomaiWarpTransmitter>();
_transmitter.OnReceiveWarpedBody += _transmitter_OnReceiveWarpedBody;
}
private void _transmitter_OnReceiveWarpedBody(OWRigidbody warpedBody, NomaiWarpPlatform startPlatform, NomaiWarpPlatform targetPlatform)
{
_cooldownActive = true;
_reenabledTime = Time.time + 5f;
_receiver = _transmitter._targetReceiver;
_transmitter._targetReceiver = null;
}
public void FixedUpdate()
{
if (_cooldownActive && Time.time > _reenabledTime)
{
_cooldownActive = false;
_transmitter._targetReceiver = _receiver;
}
}
}
}