The PowerUp
script provides functionality for collectible power-ups that temporarily affect the speed of the fire effect in Fuse Runner. There are two types of power-ups: Slow and Speed, each altering the fire’s movement for a short duration. The script plays a sound and particle effect upon collection, then destroys itself after the effect is applied.
Power-ups are a strategic gameplay element that rewards precision pathing and timing.
PowerUp
Namespace: global
Inherits from: MonoBehaviour
PowerUpType
Defines the type of speed-altering effect:
Slow
: Reduces fire speed by 50%Speed
: Increases fire speed by 150%
PowerUpType powerUpType
Specifies whether the power-up is a Slow or Speed modifier. Set via Inspector.
float effectDuration = 3f
Determines how long the power-up effect lasts in seconds.
AudioClip powerUpAudioClip
Audio clip to be played when the power-up is activated.
ParticleSystem powerUpEffect
Visual effect that plays when the power-up is triggered.
AudioSource powerUpAudioSource
Handles playback of the power-up’s sound effect.
void Awake()
Initializes required component references: ParticleSystem
and AudioSource
.
void OnTriggerEnter2D(Collider2D other)
Detects when the fire effect collides with the power-up and applies the appropriate speed modification.
FireEffectMover
on the colliding object.ApplySpeedModifier()
with values based on powerUpType
.
void PlayPowerUpEffect()
Plays the particle and sound effects associated with the power-up.
IEnumerator DestroyAfterEffect(float duration)
Waits for the effect duration (based on audio clip length) before destroying the power-up GameObject.
duration
: Time in seconds before self-destruction.
To create a power-up in a level:
GameObject
with a 2D trigger collider.PowerUp.cs
, an AudioSource
, and a ParticleSystem
.powerUpType
in the Inspector.// Example Setup
powerUpType = PowerUp.PowerUpType.Speed;
effectDuration = 3f;
Rigidbody2D
(set to Kinematic) and a Collider2D
set as trigger.