I have a lighter and when I press F I can open my lighter and when I press G it closes. I want to play a sound when F/G is pressed. I have this script that makes my lighter open and close:
var onn : AnimationClip;
var off : AnimationClip;
function Update()
{
if(Input.GetKeyDown(KeyCode.F))
animation.Play("Off");
if(Input.GetKeyDown(KeyCode.G))
animation.Play("On");
}
If i make the script like this:
var onn : AnimationClip;
var off : AnimationClip;
function Update()
{
if(Input.GetKeyDown(KeyCode.F))
animation.Play("Off");
audio.Play();
if(Input.GetKeyDown(KeyCode.G))
animation.Play("On");
audio.Play();
}
or like this:
var onn : AnimationClip;
var off : AnimationClip;
function Update()
{
if(Input.GetKeyDown(KeyCode.F))
animation.Play("Off");
audio.PlayOneShot;
if(Input.GetKeyDown(KeyCode.G))
animation.Play("On");
audio.PlayOneShot;
}
It is not gonna work. Anybody has any idea how to add a sound that play everytime i press F/G ?