I’m missing something here in the way I understand this.
What I’m trying to do is have a sound play when my player picks up and object, and then a fraction of a second later play another audio clip?
Any clue why it does not seem to be executing the “Wait for seconds”?
It seems to use it for destroying my game object but not to play the 2nd audio… I found I could put any time in there like 5 seconds and it would still just play it right away and not wait??
`function OnTriggerEnter ( other : Collider ) { // trigger events for fertilizer pellet, key, bridge, jumpPad
if ( other.tag == "jumpPad" ) // trigger object with jumpPad tag
{
jumpingFromPad = true; // set to true
isJumping_1 = false; // reset
isJumping_2 = false; // reset
isJumping_3 = false; // reset
Message ( "JumpPad activated!" ); // print that jumpPad is active
if ( other.animation != null ) // check on animation play
{
other.animation.Play ( "jumpPad_up" ); // play animation for jumpPad up
yield WaitForSeconds ( .3 ); // wait, then play down animation
other.animation.Play ( "jumpPad_down" ); // play animation for jumpPad down
}
}
if ( other.tag == "killzone" ) // trigger for the object with killzone tag
{
isKilled = true;
life -= 1; // enable player killed
}
if ( other.tag == "fertilizerPellet" )
{
fertilizerPellet += 1;
audio.PlayClipAtPoint ( fertilizerPickup, transform.position ); // Play a pick up sound for Fertilizer Pellet
Destroy ( other.gameObject );
Message ( "you have collected " + fertilizerPellet + " Fertilizer Pellet" );
}
if ( other.tag == "XtraLife" )
{
life += 1;
audio.PlayClipAtPoint ( xtraLifePickup, transform.position ); // Play a pick up sound for Extra Life
Destroy ( other.gameObject );
Message ( "you have collected " + life + " Extra Life" );
}
if ( other.tag == "XtraHealth" )
{
health += 25;
audio.PlayClipAtPoint ( xtraHealthPickupMagic, transform.position ); // Play magic sound for Extra Health pick up
yield WaitForSeconds ( audio.clip.length );
audio.PlayClipAtPoint ( xtraHealthPickup, transform.position ); // Play a pick up sound for Extra Health pick up (SweeeT!)
Destroy ( other.gameObject );
Message ( "you have collected " + health + " Extra Health" );
}
if ( other.tag == "key" )
{
key += 1;
audio.PlayClipAtPoint ( keyPickupSound, transform.position ); // Play a key Pick Up audio clip
Destroy ( other.gameObject );
Message ( "you have collected " + key + " keys" );
}
if ( other.tag == "level01ExitDoor" )
{
if ( key < 2 )
{
Message ( "You need 2 keys to unlock the exit door" );
}
if ( key == 2 )
{
key = 0;
audio.PlayClipAtPoint ( doorOpenSound, transform.position ); // Play a door open Up audio clip
other.animation.Play ( "exitDoorOpen" );
Message ( "Your keys unlocked the exit Door!" );
}
}
if ( other.tag == "bogDeath" ) // trigger for Mud Bog Death
{
//animation.Play ( aniMudDrown.name );
//yield WaitForSeconds (0.2);
Instantiate ( bogDeathParticle, transform.position, Quaternion.identity );
audio.PlayClipAtPoint ( dieSound, transform.position ); // Play a dying audio clip (blood Splat)
yield WaitForSeconds (.1);
isKilled = true;
life -= 1;
}
if ( other.tag == "level01Exit" ) // Trigger for exit to Level 02
{
yield WaitForSeconds (0.2); // Waits 0.2 of a second before loading next scene
Application.LoadLevel ("ThanksForPlaying"); // Loads scene 02 on entering trigger collider
}
if ( other.tag == "BudsDoor" )
{
audio.PlayClipAtPoint (doorOpenSound, transform.position ); // plays sound of Door opening when Player hits Collider
yield WaitForSeconds (0.2); // Waits 0.2 of a second before loading next scene
Application.LoadLevel ("LevelLoader001");
}
}`