Blog Archives
[Code] Heartbeat sound when life is low
Big Thanks to Crusha K. Rool and 100GPing100 from UDK Forums.
Use this code in your custom Pawn class:
class MyNewPawn extends UTPawn;
var AudioComponent HealthSound;
event TakeDamage(int DamageAmount, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{
super.TakeDamage(DamageAmount, EventInstigator, HitLocation, Momentum, DamageType, HitInfo, DamageCauser);
if (Health <= 25)
{
HealthSound.Play();
}
}
function Tick(float DeltaTime)
{
Super.Tick(DeltaTime);
if (Health > 25)
HealthSound.Stop();
}
simulated event Destroyed()
{
HealthSound = None;
super.Destroyed();
}
defaultproperties
{
Begin Object class=AudioComponent name=MenuAudioComponent
SoundCue = SoundCue'Sounds.Misc.Heartbeat_Cue' //Change this to your soundcue.
End Object
HealthSound = MenuAudioComponent
Components.Add(MenuAudioComponent)
}
