- Home /
repeated player collisions
I have found several ways to make a sound play when the guided object or player hits another object, but the sound only plays on the first hit. I have a number of object I want to play sound EVERY time they are hit by the guided object or player.
I have a script here which I like because it has the potential to trigger various sounds depending on the velocity of the hit, that I can figure out. But how can I get a sound to play EVERY time the object is hit and not just the first time? I have ploughed through Unity Answers but have not yet found one.
Thank you very much.
#pragma strict
var impact : AudioClip;
function OnCollisionEnter (hit : Collision)
{
if(hit.relativeVelocity.magnitude >= 5)
{
audio.PlayOneShot (impact);
}
}
Answer by jenci1990 · Dec 05, 2014 at 12:59 PM
#pragma strict
var impact : AudioClip;
function OnCollisionEnter (hit : Collision) {
if (hit.relativeVelocity.magnitude >= 5) {
AudioSource.PlayClipAtPoint( impact, transform.position);
}
}
Thanks that works perfectly and I can set up several variables to play a louder noise the harder the hit! Brilliant!
Answer by FirePlantGames · Dec 09, 2014 at 04:43 PM
Don't post a comment as an answer (It's frowned upon by the unity admin mechs) and also accept the answer...
the rules on using Unity answers are so confusing that I really dislike using it. Any site that needs a video to explain what you are supposed to do is badly designed. I am completely at a loss as to why we can't all just talk to each other without constant harassment about breaking some rule that doesn't make sense in the context of the thread. It makes it really hard to understand other peoples threads when the answers and the questions don't relate to each other.
"It makes it really hard to understand other peoples threads when the answers and the questions don't relate to each other."
UA "threads" do not operate like a discussion forum. They each start with a single, specific technical question, and then people propose different possible answers. When one of those answers solves the problem, the original poster should mark it as the correct solution. That way, anyone facing a problem in the future needs only to search whether the question has already been asked and, if so, simply looks up the accepted answer.
For this system to work, the only time you hit the "Post Answer" button should be when you are attempting to solve the original question. Any additional information/queries/requests for clarification should be posted as "Comments" under the respective answer/question. And, importantly, questioners must mark the answer that actually solved their problem by clicking the tick mark next to the appropriate answer...
Your answer
Follow this Question
Related Questions
Play sound on collision 1 Answer
only one onCollisionEnter event is detected 1 Answer
Play An Audio Clip When An Instantiated Object Collides 1 Answer
Play sound on collision doesnt work 3 Answers
loop animation while audio is playing 0 Answers