Hello everyone
Please help
Sorry for the big text
I moved away from Rick’s video for a bit and ran into a problem
My ship is constantly flying forward
The W key raises the ship up
S - down
A - left
D - right
I want to
- The “engine sound” was constant, but when you press the WASD keys, the “engine sound” turned off
- When pressing the WASD keys, the displacement sound turned on
I completed the first task using AudioSource:
AudioSource droneMoveAudio;
void ForwardSpeed()
{
if (Input.GetKey(KeyCode.W))
{
if (droneMoveAudio.isPlaying)
{
droneMoveAudio.Stop();
}
}
else if (Input.GetKey(KeyCode.S))
{
if (droneMoveAudio.isPlaying)
{
droneMoveAudio.Stop();
}
}
else if (Input.GetKey(KeyCode.A))
{
if (droneMoveAudio.isPlaying)
{
droneMoveAudio.Stop();
}
}
else if (Input.GetKey(KeyCode.D))
{
if (droneMoveAudio.isPlaying)
{
droneMoveAudio.Stop();
}
}
else if(!droneMoveAudio.isPlaying)
{
droneMoveAudio.Play();
}
}
Now I need to create a method that will turn on a different sound when WASD is pressed, and turn that sound off when the keys are turned off
I first created a AudioClip to put it in a method similar to the first one. But in the AudioClip there are no Stop and Play functions
I do not know what to do
Maybe it is possible to assign properties AudioSourse to AudioClip so that there is access to the functions Play and Stop?