My code is almost similar to Ben’s and mine too does not stop playing sound when I hit something. I know he will fix this later but I’m curious so just wanted to know that…
AudioSource thrustSound; // for the sound
bool playSound = false; // iff true, the music plays
// Start is called before the first frame update
void Start()
{
// initializing the rigidbody with the rocket rigidbody component
rigidBody = GetComponent<Rigidbody>();
thrustSound = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if (state == State.Alive)
{ // if alive then process the input else dont
Thrust();
PlaySound();
}
}