Search Unity

Collision audio file continuously repeating

Discussion in 'Scripting' started by DTard, Apr 3, 2014.

  1. DTard

    DTard

    Joined:
    Mar 31, 2014
    Posts:
    9
    Here's my code:

    Code (csharp):
    1. function OnCollisionEnter(collision : Collision) {
    2. var collMag = collision.relativeVelocity.magnitude;
    3. isGrounded = true;
    4. jumpNum = 2;
    5.     if (collMag > 100000); {
    6.         AudioSource.PlayClipAtPoint(collideSound, rigidbody.position);
    7.         }
    8. }
    I tried the if statement to check that the collision is of a certain force, but it didn't change anything. the audio file repeatedly loops when the player is not moving while on the platform.

    any ideas?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Check the properties of the audio source component aren't set to loop?
     
    Last edited: Apr 3, 2014
  3. DTard

    DTard

    Joined:
    Mar 31, 2014
    Posts:
    9
    Should i be seeing that setting in the inspector when I select the sound file? or is it elsewhere?


    EDIT: that semicolon on the if statement line was ruining everything. Now, the sound stops while standing still on the ground. However, when my object starts rolling, the sound starts repeatedly playing again. Is there some way to avoid playing the sound when the force being applied is rotational torque?
     
    Last edited: Apr 4, 2014
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  5. DTard

    DTard

    Joined:
    Mar 31, 2014
    Posts:
    9
    Thanks. Turned out not to be the problem though. Ended up solving it with raycasting and setting up a little timer.