UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 6

179

var() SoundCue SoundOnDestroy;

/** Particles to play when destroyed. */
var() ParticleSystem ParticlesOnDestroy;

/** Allows particles to be turned on/off. */
var() ParticleSystemComponent PSC;

/** Static mesh to spawn as physics object when destroyed. */
var() StaticMesh SpawnPhysMesh;

/** Time between being destroyed & respawning. */
var() float RespawnTime;

/** Set the mesh back to the original upon respawning */
var StaticMesh RespawnSM;

/** Is the barrel currently destroyed? */
var bool bDestroyed;

/** Time before we are going to respawn. */
var float TimeToRespawn;


  1. Our first function is simply PostBeginPlay(). Here we set RespawnSM
    (respawn static mesh) to use our static mesh component.
    /****

    • Setting respawn mesh to use our static mesh
      ****/
      simulated function PostBeginPlay()
      {
      Super.PostBeginPlay();




// Uses this mesh when respawning
RespawnSM = StaticMeshComponent.StaticMesh;
}

When our barrel explodes, we'll need a way to set it back to its original condition
when it respawns. We do this with the RespawnDestructable() function. Here,
we reset the static mesh and then reattach the static mesh component. Additionally,
we turn off the particle system, so that we no longer see the smoke and fire from the
previously destroyed barrel.

/********************************************************
* Place destroyed item back in original condition
********************************************************/
Free download pdf