How do I trigger a sound when the player hits a platform?
How do I trigger a sound when the player hits a platform? I want specific platforms to play their own sounds, but I can't do that. I don't know anything about C#, so I can't do it. Can you help?
Answer by Cains · Nov 02, 2016 at 11:47 PM
You'll need to create a new script and attach it to your platform GameObjects. Also attach an AudioSource component and a collider component to them as well. In your new script, you will want to store the AudioSource component as a variable and create an OnCollisionEnter, OnTriggerEnter, OnCollisionEnter2D, or OnTriggerEnter2D method depending on your needs. That method will be called when another collider hits your platform's collider, so in that method you will want to call the Play or PlayOneShot method on the AudioSource variable.
You can put different audio clips into the AudioSource components on your platforms for different sounds, or store different audio clips as variables and use them in PlayOneShot.
I can try to provide some examples if needed, but you are going to have to learn at least a little bit of C# if you want to truly use Unity -- it's how you tell it what you want to do.
Your answer
Follow this Question
Related Questions
Help me with gui please (C#) 2 Answers
Player Can Not get off platform 1 Answer
How do I not trigger animation during play state of the triggered animation. 1 Answer
2D Power up script not working 0 Answers
Setting up a function for sorting specific triggers entered based on a height integer. 0 Answers