- Home /
How to play a sound effect
Hello,
This is a two part question:
1) How do you make a sound effect play once a specific keyboard key is pressed R or Enter etc.
2) How do you make a sound effect play once some object collides with another object.
Thank you for your time.
Answer by syclamoth · Mar 14, 2012 at 12:37 AM
Part 1-
Very simple:
if(Input.GetKeyDown(Keycode.R))
{
audio.Play();
}
Part 2-
Similar to part 1, except that it goes inside OnCollisionEnter.
Please, read the documentation before asking questions here. It makes life generally easier for all of us.
Im sorry I thought If I didn't know something I needed to ask a question. I also did not know of the documentation.
Did you know that if you Google for 'How do I play a sound Unity', the first hit is the script reference? You need to learn how to find out things for yourself.
Your answer
Follow this Question
Related Questions
Detect only UI button click 3 Answers
Play Animation and Sound when enter collider 1 Answer
drag and drop into other cells 1 Answer
Restart sound when re-entering trigger? 2 Answers