collision between two objects

It’s a little silly question but I’m confused about how can I say in javascript that two specific objects are OnCollisionEnter??

// If some object with a certain name collides with this object, do something
function OnCollisionEnter (collision : Collision)
{
      if (collision.gameObject.name == "whatever")
      {
             // do stuff
      }
}

so if I wan to do something when object A collides with object B, then I should attach a script to object A that says:

function OnCollisionEnter (collision : Collision) 
{ 
      if (collision.gameObject.B == "whatever") 
      { 
             // do stuff 
      } 
}

what does the “whatever” represents? A true or false state maybe? Or the script works without even write it?

That is the name of the object that it collides with

This is how it would look then:

// ObjectA.js

function OnCollisionEnter (collision : Collision)
{
     // if the collider that objectA collides with's name is "objectB"
     if (collisoin.gameObject.name == "objectB")
     {
         // then do something
     }
}

to be more specific. I have a timer, a road (Plane01) and a car. What I want is to start playing an object’s audioclip, when the car collides with the road and the timer is lower than 5 secs.

I have this:

function Update () {
	
  	
    if ((seconds < 5)  (collision.gameObject.Plane01)) {
    	 
    GameObject.Find("Bass").GetComponent(AudioSource).volume = 1;
      
    }
}

but it doesn’t work. How can I specify in the script that the car is colliding with the road??

function OnCollisionEnter (collision : Collision) {
    if ((seconds < 5)  (collision.gameObject.name == "Plane01")) {
    GameObject.Find("Bass").GetComponent(AudioSource).volume = 1;     
    }
}

yeah, I try it, it’s right but it doesn’t work, probably because i have attached to the Plane01 the following script:

function OnCollisionEnter () {
	for (var j=0.0;j<1.1;j+=0.1) {
			audio.volume = j; 
			yield WaitForSeconds (0.01);
			
	}
}
function OnCollisionExit () {
	if (audio.volume > 0.0){
	for (var k=1.1;k>0.0;k-=0.1) {
			audio.volume = k-0.1; 
			yield WaitForSeconds (0.01);
		
	}
  }
}

I have to work it out somehow now. Thanx anyway!! :smile:

EDIT: Well, it seems that I have to use a OnCollisionStay function instead of enter.