Fixed LaserBeam Bug

This commit is contained in:
Hazim Bin Ijaz 2025-09-13 02:08:34 +05:00
parent 49362fcd87
commit f3d30841e3
2 changed files with 14 additions and 16 deletions

View File

@ -134,16 +134,17 @@ public class LaserBeam : MonoBehaviour
// LaserBeam.cs — replace SetLaserPhase with this version
public void SetLaserPhase(LaserPhase phase)
{
// If were externally controlled, cancel any internal coroutines immediately
if (externalControl)
{
StopAllCoroutines();
introRunning = false;
}
if (!line) SetupLaserRenderer();
if (!line) SetupLaserRenderer(); // make sure 'line' exists even if GO was inactive
// Always clear when entering lethal/lead-in phases
if (phase == LaserPhase.Firing || phase == LaserPhase.Charging)
hasTriggeredDeathThisBurst = false;
if (phase != currentPhase) hasTriggeredDeathThisBurst = false;
currentPhase = phase;
switch (phase)
@ -162,7 +163,6 @@ public class LaserBeam : MonoBehaviour
UpdateLaserPath();
line.enabled = true;
SetLineColor(laserColor);
hasTriggeredDeathThisBurst = false;
CheckHit();
break;
}

View File

@ -45,7 +45,9 @@ public class LaserBeamController : MonoBehaviour
StartCoroutine(RunBatches());
}
IEnumerator RunBatches()
IEnumerator RunBatches()
{
while (true) // <— keep cycling batches forever
{
for (int bi = 0; bi < batches.Count; bi++)
{
@ -69,21 +71,19 @@ public class LaserBeamController : MonoBehaviour
// Loop phases for the duration of this batch
while (Time.time < batchEnd)
{
// Compute runway required to complete a Charge->Fire sequence
float runway = Mathf.Max(0f, chargingWindup) + Mathf.Max(0f, fireDuration);
float timeLeft = batchEnd - Time.time;
// If not enough time to do Charging+Firing, just stay Idle until the batch ends.
if (timeLeft < runway)
{
// Stay idle until batch end
yield return PhaseBlock(LaserPhase.Idle, timeLeft, batchEnd);
break;
}
// IDLE
float idleTime = Mathf.Max(0f, idleBeforeCharge);
// If idleTime itself would consume too much and leave < runway, trim idle to fit
if (idleTime > 0f && idleTime > timeLeft - runway)
if (idleTime > timeLeft - runway)
idleTime = Mathf.Max(0f, timeLeft - runway);
if (idleTime > 0f)
@ -92,21 +92,19 @@ public class LaserBeamController : MonoBehaviour
if (Time.time >= batchEnd) break;
}
// CHARGING (blink)
if (chargingWindup > 0f)
{
yield return PhaseBlock(LaserPhase.Charging, chargingWindup, batchEnd);
// we guaranteed runway, so we should still have time left for Firing
}
// FIRING (lethal)
if (fireDuration > 0f)
{
yield return PhaseBlock(LaserPhase.Firing, fireDuration, batchEnd);
}
}
// After each batch, force a clean Idle/off so nothing stays lit
SetPhaseForAll(LaserPhase.Idle);
}
}
}
// Set phase for all active lasers and tick per-frame for 'duration' (clamped by batch end)
IEnumerator PhaseBlock(LaserPhase phase, float duration, float batchHardEnd)