How can i make an object play sound when pressing a button ?

Hello i’m bit new to games programming !

I was wondering if anybody could help me out.
i have this phonograph object in my scene, i want to play audio when pressing a button ‘E’
anybody could help me with :slight_smile: !!!

You can find the answer to your question in the Documentation of Unity
It is recommended to use the Input manager and setup a button however you wish to name it, i name it “action” for now. then you say which input is going to take type “e”. now you can call that in script:

void Update(){

if(input.GetButtonUp("action")){

AudioSource.Play(yourclip);

}

}

You can find lots of tutorials and also the Unity Documentation is very handy,:

Thankyou lukasgmusic very helpful

1 Like