Fixed LaserBeam Bug
This commit is contained in:
parent
49362fcd87
commit
f3d30841e3
@ -134,16 +134,17 @@ public class LaserBeam : MonoBehaviour
|
|||||||
// LaserBeam.cs — replace SetLaserPhase with this version
|
// LaserBeam.cs — replace SetLaserPhase with this version
|
||||||
public void SetLaserPhase(LaserPhase phase)
|
public void SetLaserPhase(LaserPhase phase)
|
||||||
{
|
{
|
||||||
// If we’re externally controlled, cancel any internal coroutines immediately
|
|
||||||
if (externalControl)
|
if (externalControl)
|
||||||
{
|
{
|
||||||
StopAllCoroutines();
|
StopAllCoroutines();
|
||||||
introRunning = false;
|
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;
|
currentPhase = phase;
|
||||||
|
|
||||||
switch (phase)
|
switch (phase)
|
||||||
@ -162,7 +163,6 @@ public class LaserBeam : MonoBehaviour
|
|||||||
UpdateLaserPath();
|
UpdateLaserPath();
|
||||||
line.enabled = true;
|
line.enabled = true;
|
||||||
SetLineColor(laserColor);
|
SetLineColor(laserColor);
|
||||||
hasTriggeredDeathThisBurst = false;
|
|
||||||
CheckHit();
|
CheckHit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,9 @@ public class LaserBeamController : MonoBehaviour
|
|||||||
StartCoroutine(RunBatches());
|
StartCoroutine(RunBatches());
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator RunBatches()
|
IEnumerator RunBatches()
|
||||||
|
{
|
||||||
|
while (true) // <— keep cycling batches forever
|
||||||
{
|
{
|
||||||
for (int bi = 0; bi < batches.Count; bi++)
|
for (int bi = 0; bi < batches.Count; bi++)
|
||||||
{
|
{
|
||||||
@ -69,21 +71,19 @@ public class LaserBeamController : MonoBehaviour
|
|||||||
// Loop phases for the duration of this batch
|
// Loop phases for the duration of this batch
|
||||||
while (Time.time < batchEnd)
|
while (Time.time < batchEnd)
|
||||||
{
|
{
|
||||||
// Compute runway required to complete a Charge->Fire sequence
|
|
||||||
float runway = Mathf.Max(0f, chargingWindup) + Mathf.Max(0f, fireDuration);
|
float runway = Mathf.Max(0f, chargingWindup) + Mathf.Max(0f, fireDuration);
|
||||||
float timeLeft = batchEnd - Time.time;
|
float timeLeft = batchEnd - Time.time;
|
||||||
|
|
||||||
// If not enough time to do Charging+Firing, just stay Idle until the batch ends.
|
|
||||||
if (timeLeft < runway)
|
if (timeLeft < runway)
|
||||||
{
|
{
|
||||||
|
// Stay idle until batch end
|
||||||
yield return PhaseBlock(LaserPhase.Idle, timeLeft, batchEnd);
|
yield return PhaseBlock(LaserPhase.Idle, timeLeft, batchEnd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IDLE
|
// IDLE
|
||||||
float idleTime = Mathf.Max(0f, idleBeforeCharge);
|
float idleTime = Mathf.Max(0f, idleBeforeCharge);
|
||||||
// If idleTime itself would consume too much and leave < runway, trim idle to fit
|
if (idleTime > timeLeft - runway)
|
||||||
if (idleTime > 0f && idleTime > timeLeft - runway)
|
|
||||||
idleTime = Mathf.Max(0f, timeLeft - runway);
|
idleTime = Mathf.Max(0f, timeLeft - runway);
|
||||||
|
|
||||||
if (idleTime > 0f)
|
if (idleTime > 0f)
|
||||||
@ -92,21 +92,19 @@ public class LaserBeamController : MonoBehaviour
|
|||||||
if (Time.time >= batchEnd) break;
|
if (Time.time >= batchEnd) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHARGING (blink)
|
|
||||||
if (chargingWindup > 0f)
|
if (chargingWindup > 0f)
|
||||||
{
|
|
||||||
yield return PhaseBlock(LaserPhase.Charging, chargingWindup, batchEnd);
|
yield return PhaseBlock(LaserPhase.Charging, chargingWindup, batchEnd);
|
||||||
// we guaranteed runway, so we should still have time left for Firing
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIRING (lethal)
|
|
||||||
if (fireDuration > 0f)
|
if (fireDuration > 0f)
|
||||||
{
|
|
||||||
yield return PhaseBlock(LaserPhase.Firing, fireDuration, batchEnd);
|
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)
|
// Set phase for all active lasers and tick per-frame for 'duration' (clamped by batch end)
|
||||||
IEnumerator PhaseBlock(LaserPhase phase, float duration, float batchHardEnd)
|
IEnumerator PhaseBlock(LaserPhase phase, float duration, float batchHardEnd)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user