My first script, and I need some help.

Made a previous post concerning playing audio on collision, and ended up with this code…
#pragma strict

function Start () {

var play;
	if pause = true 
		function OnCollisionEnter(collision : Collision) {
    // Debug-draw all contact points and normals
    for (var contact : ContactPoint in collision.contacts) {
        Debug.DrawRay(contact.point, contact.normal, Color.white);
    }
    
    // Play a sound if the coliding objects had a big impact.        
    if (collision.relativeVelocity.magnitude > 2)
        audio.Play();
}

var pause;
		if play = true
		function OnCollisionEnter(collision : Collision) {
    // Debug-draw all contact points and normals
    for (var contact : ContactPoint in collision.contacts) {
        Debug.DrawRay(contact.point, contact.normal, Color.white);
    }
    
    // Play a sound if the coliding objects had a big impact.        
    if (collision.relativeVelocity.magnitude > 2)
        audio.Pause();
}


}

function Update () {

}

I know there’s stuff wrong with it, but could someone just blunty tell me or fix it so I can learn from a side by side comparison? I’m not very good at learning in bits and pieces.

Thans - Sir Paddles of Loxely

Here is a rewrite of your script.

var playing = false;

function OnCollisionEnter(collision : Collision)
{
    // Debug-draw all contact points and normals
    for (var contact : ContactPoint in collision.contacts) {
        Debug.DrawRay(contact.point, contact.normal, Color.white);
    }

// Play/pause a sound if the colliding objects had a big impact.        
	if (collision.relativeVelocity.magnitude > 2) {
		if (playing)
	   	 	audio.Pause();
	   	else
	   		audio.Play();
	   		
	   	playing = !playing; // flips value
	}
}

A couple pointers. You cannot have the same function twice in a script as you have OnCollisionEnter(). You shouldn’t nest functions as you have with your OnCollisionEnter’s inside of the Start() function. You should lookup the syntax of the if statment and also take a look at how elements are compared. The ‘=’ by itself is for assignment not comparison.