How do I play sound when a key is pressed
9 views (last 30 days)
Michael Mauricio on 6 Dec 2016
I am creating a game in matlab, how do I modify my code to play a sound when ever my character shoots (shoot key is pressed).
This is what I have so far, a working gun.
if(gamepad.isPressed(2)&& trigger_state == 0)
bullet_speed = 2500;
if (bullet_speed ==0)
Kirby Fears on 6 Dec 2016
Edited: Kirby Fears on 6 Dec 2016
This article describes how to record and play sound.
If you have a specific sound file that you need to play, try searching for that file type on this forum. However, I imagine it will be lots of fun recording your own sound effect as described in the link above.
Hope this helps.