Play sound on collision

It’s a very basic script, but i didn’t found anything like this in the web, so, i will ask here, but as i said, it’s very simple i am just too bad to know what to do xD (seriously, i am new to scripting).

I made a simple script that play a sound everytime ANYTHING touches the collider of my object.

#pragma strict

var bipsoundClip:AudioClip;

function OnTriggerEnter(o:Collider){


    GetComponent.<AudioSource>().PlayOneShot(bipsoundClip);
}

Let’s say i have a cube named “Atlas”, (it’s just an example) i want to play my sound “bipsound” everytime a SPECIFIC object collides with my cube Atlas. How can i do this?
PS: Only a SPECIFIC object/prefab, not the other ones. And i want it to loop.

AudioSource has the atribute Loop just set it to true.

There are many ways to check which object is colliding, one is checking the name atribute of the collider and make a if statement to compare with the ones you want, like:

if(other.gameObject.name == "MyObject")
{
       //Do something
}

You can also do it with tags or even with a specific atribute from a specific componente, like:

//You should check if the componente is null in case of many objects with different components colliding.
if(other.transform.GetComponent<ScriptName>().myVariable == value)
{
   //Do something
}

You can create a custom tag for that specific object, assign that tag to the object you want, then in the script you can do something like this.

function OnTriggerEnter(other : Collider)
{
if (other.transform.tag == "your tag")
{
GetComponent.<AudioSource>().PlayOneShot(yoursound);
}
}`

Try attaching this script (and the audio source) to the specific object (that way when that object collides with something else - the cube - it will play the sound).

This for the looping: How to play loop an audio clip on button hold down? - Questions & Answers - Unity Discussions . (Sorry don’t have a java version).

Alternatively try clicking loop audio on audio source.

Hope this helps.