Hi,
Instead of the boring silence when in idle mode I wanted to add a sound effect where the rocket is not on “afterburn” mode (a bit more decent tune). However, when it comes to coding I dont get it to work that
- Play idle sound
- If input Space; stop idle sound and immediately start thrust sound
- when releasing space stop playing thrust sound and play idle sound
- loop
The only thing I could imagine is if I add another condition in the switch and play it there. Any efficient solutions?
[SerializeField] AudioClip mainEngine;
[SerializeField] AudioClip GameOver;
**[SerializeField] AudioClip IdleThrust;**
[SerializeField] AudioClip Success;
then I state in update that it should play the idle sound:
void Update() {
{ audioSource.PlayOneShot(IdleThrust); }
....
....
public void Thrust()
{
float Booster = mainThrust * Time.deltaTime;
audioSource.PlayOneShot(IdleThrust);
if (Input.GetKey(KeyCode.Space))
ApplyThrust(Booster);
else
{
audioSource.Stop();
}
} private void ApplyThrust(float Booster)
{
rigidBody.AddRelativeForce(Vector3.up * Booster);
if (audioSource.isPlaying == true) //no sound overlay
audioSource.Stop();
else
{ audioSource.PlayOneShot(mainEngine); }