FuseBurner
is a gameplay component responsible for detecting when the player’s drawn fuse intersects with the ignition source. It handles initiating the burn process, managing audio playback, and ensuring fire progression respects a timed constraint. This script also ensures that the fire effect is positioned correctly and begins traversal from the closest relevant fuse point.
This script is essential for synchronizing the ignition sequence, player interaction, and fail conditions based on timing.
FuseBurner
Namespace: global
Inherits from: MonoBehaviour
AudioClip fuseBurningAudioClip
The sound effect that plays while the fuse is actively burning.
FireEffectMover fireEffectInstance
Reference to the existing FireEffectMover
instance in the scene, responsible for animating fire along the fuse path.
float burnSpeed
Speed at which the fuse is consumed (used internally to manage fire pace).
float maxBurnTime
Maximum allowed burn duration, typically set by the game timer.
List<Vector2> fusePath
The current list of waypoints representing the drawn fuse path.
bool isBurning
Tracks whether the fuse is currently active and burning.
float burnTimer
Elapsed time since the fuse was ignited.
LineRenderer fuseLineRenderer
Reference to the LineRenderer
on the active fuse.
AudioSource fuseBurnerAudioSource
Audio source responsible for playback of the fuse burning sound effect.
GameTimer gameTimer
Reference to the scene’s game timer component, used to initialize maxBurnTime
.
void Awake()
Initializes references to the fire effect, audio source, and game timer. Also sets maxBurnTime
from the timer at game start.
void Start()
Ensures the fire effect is positioned at the burner’s location at the beginning of gameplay.
void Update()
If the fuse is burning, it tracks the burn duration and triggers failure if the timer exceeds the allowed maximum.
void OnTriggerEnter2D(Collider2D collision)
Handles collision detection with a placed fuse line. If the collision is valid, it calculates the closest point to ignite and starts the fire sequence.
"FuseLine"
and that it’s been placed.LineRenderer
component.
List<Vector2> ExtractPathFromLineRenderer(Vector2 touchPoint)
Builds a list of fuse path points and determines the closest index to the ignition source. Returns a sub-path starting from that index.
touchPoint
: The world-space point used to determine the nearest fuse point.List<Vector2>
: A list of waypoints starting from the closest point.void StartBurning()
Begins the burn sequence by assigning the path to the FireEffectMover
, resetting timers, and playing the fuse audio.
void FuseBurnedOut()
Triggers a game-over sequence when the fuse times out. Stops audio playback and notifies the GameOverManager
.
void OnTriggerEnter2D(Collider2D collision) {
if (collision.CompareTag("FuseLine")) {
fuse_draw fuse = collision.GetComponent<fuse_draw>();
if (fuse.isPlaced) {
Vector2 point = collision.ClosestPoint(transform.position);
fusePath = ExtractPathFromLineRenderer(point);
StartBurning();
}
}
}
FireEffectMover
is present in the scene and properly referenced.GameTimer
should be initialized before the game starts to set maxBurnTime
.isPlaced == true
) should trigger ignition.ClosestPoint
to determine direction and avoid incorrect pathing.