Hi there;
I’m trying to script audio for a dog in my game so that when the key is pressed, the audio plays.
This part I’ve got sorted, but what I wanted to do was,
A = Make it so that the other audio can’t be activated when the other is playing, like, you can’t howl if you’re barking. So I guess, making it so that the others can’t be pressed till a certain duration.
I started working on this but was hoping for a more efficient way of doing it. Here is the relevant code I was working on:
{
// Whine
public AudioSource whineAudio;
public bool canWhine;
public float whineTime;
public bool isWhining;
// Bark
public AudioSource barkAudio;
public bool canBark;
public float barkTime;
public bool isBarking;
// Howl
public AudioSource howlAudio;
public bool canHowl;
public float howlTime;
public bool isHowling;
void Update()
{
Audio();
}
void Audio()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
isWhining = true;
whineAudio.Play();
}
else if (Input.GetKeyUp(KeyCode.Alpha1))
{
isWhining = false;
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
isBarking = true;
barkAudio.Play();
}
else if (Input.GetKeyUp(KeyCode.Alpha2))
{
isBarking = false;
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
isHowling = true;
howlAudio.Play();
}
else if (Input.GetKeyUp(KeyCode.Alpha3))
{
isHowling = false;
}
}
The second thing I wanted to do was make it so that the button for howling had to be held for a certain duration before the Audio played
Sorry for the incomplete code for the task but was really hoping to find a better way of doing it. Thank you very much!