Ok so when my player hits a wall (Enemy tag). My player is destroyed after a certain amount of time. During this time, I disabled the mesh renderer on impact so it "appears" as if the player is destroyed.
I have some sounds I want to play upon impact. One is 'game over" sound and one is an "explosion sound".
right now, when they play at the same time, they interfere with each other, causing the game over not to be heard correctly.
I wanted to delay the output of "game over" by 3 seconds. So the explosion is over. Play the 'Game over sound' and then destroy the player.
This is my code so far, but the compiler tells me that now OnTriggerEnter cannot be an iterator block now that I have a yield function. Is there any way to just delay the output of the game over sound without creating a whole new function for the game over sound and using Play Delayed?
and if I do have to use Play delayed, how do I set the volume of the sound? as right now I am using PlayOneShot
// function to detect whether collision is with a pick-up cube or an emeny wall.
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("PickUp"))
{
// if pick-up object. Pick it up!
float vol = Random.Range(volLowRange, volHighRange);
playerSource.PlayOneShot(coinSound, vol);
other.gameObject.SetActive(false);// other.gameObject should destroy here by the way.
getCount = GameObject.FindGameObjectsWithTag("PickUp");
count = getCount.Length;
countCollected = countCollected + 1;
SetCountText();
if (count < 10)
{
// spawns new pick-up objects
Invoke("SpawnObject", 2.0f);
}
}
if (other.gameObject.tag == "Enemy")
{
// if enemy wall... kill the player it is game over
rend.enabled = false;
float vol = Random.Range(volLowRange, volHighRange);
playerSource.PlayOneShot(deathSound, voldeath);
playerSource.PlayOneShot(explosion, volex);
yield return new WaitForSeconds (3);
playerSource.PlayOneShot(gameOver, volgo);
deathText.text = "GAME OVER!";
Destroy(Player.gameObject, deathTime);
}
}
Note: before the addition of yield the code runs perfectly and does everything I want it to.
Thanks for any help you can provide