The WatterPuddle
script represents a hazard in the game world that extinguishes fire effects upon contact. It handles both visual and audio feedback when a ParticleSystem
(representing fire) enters its trigger zone. Upon extinguishing, it also signals a game-over condition by invoking the GameOverManager
.
This script adds strategic challenge by forcing players to avoid certain environmental obstacles while planning their fuse path.
WatterPuddle
Namespace: global
Inherits from: MonoBehaviour
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(ParticleSystem))]
Ensures that any GameObject using this script will also have the required AudioSource
and ParticleSystem
components.
ParticleSystem extinguishEffect
A reference to the particle effect that plays when the fire is extinguished. Must be assigned in the Inspector.
AudioSource audioSource
The audio source used to play the extinguishing sound effect. Automatically fetched from the GameObject on Awake.
AudioClip fireExtinguishingClip
The sound clip that plays when the fire is extinguished.
void Awake()
Performs all necessary component validations and initial setup.
AudioSource
and ParticleSystem
components.
void OnTriggerEnter2D(Collider2D other)
Detects when an object (such as the fire effect) enters the puddle and applies extinguishing behavior.
TryGetComponent<ParticleSystem>
to detect fire.GameOverManager.ShowGameOver(false)
to end the level.Collider2D other
: The collider entering the water hazard.
To use WatterPuddle
in a scene:
2D Collider
(set to Is Trigger
).WatterPuddle.cs
, an AudioSource
, and a ParticleSystem
.// Automatically handled
OnTriggerEnter2D(Collider2D other)
ParticleSystem
for proper detection.loop = false
, playOnAwake = false
).