Hello,
How do you make a audio file trigger from pressing a certain key? Such as:
-Press up = play audio 1
-Press down = Play audio 2
etc.
Thank You
Hello,
How do you make a audio file trigger from pressing a certain key? Such as:
-Press up = play audio 1
-Press down = Play audio 2
etc.
Thank You
You’re looking for something like this:
AudioSource source1;
AudioSource source2;
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
source1.Play();
if (Input.GetKeyDown(KeyCode.DownArrow))
source2.Play();
}
You have to make sure an audiofile is actually loaded into the variables source1 and source2 before you play them, of course. You might benefit from reading the information at: