How do I play Audio in Java?

I have been doing some college work and i am trying to make it so when i click to shoot it plays a sound! I have the “var ShootSound : AudioSource” i just need the line of code to trigger the sound to play.

Can someone please help me!

Thanks.

-SD2020_

Unity doesn’t use “Java”, thats entirely different. Unity supports a version of javascript, which isn’t the same as javascript used elsewhere, usually the term “unityscript” is used to help disambiguate.

I am aware, but i have done audio in javascript in unity before but confused if it was changed in unity 5. Would you know the line of code i would use to play the audio?

follow link, watch the tutorials… there is one on scripting and one that covers the changes that came in unity 5, they explain it far more succinctly than a forum will.

.play() on reference to a audio clip

audioclips don’t have a play function… audiosources do. Setting the audiosource to play the correct clip is covered in the tutorials.

Could you please give me an idea of what it would look like?