Collider Issues

Hey guys, here is the problem:

I have a sonar like object (represented by a sphere) that expands, then contracts when the sonar pulse hits a certain diameter. There are also other game objects littered around the game area. What I want is when the sonar pulse hits any one of the game objects, that object will make a sound. I wrote this tiny script but it only works when the object the script is attached to is moving and it collides with another object.

Here is the script:

function OnCollisionEnter(coll:Collision) {
	noise.audio.Play();
}

function Start(){
	//OnCollisionEnter();
	

}

Here is the script that makes the sphere expand and contract:

//var speed : int = 1;
var speed001 : double;
var maxScale : double = 7;
var minScale : double = 1;
var loopHandle : boolean = true;
var growSwitch : boolean = false;
 
function Start(){
    BiggerSmaller();
    Debug.Log("Start Fucntion");
}
 
function Update () {
}
 
function Grow(){
    transform.localScale += Vector3(0.05+speed001,0.05+speed001,0.05+speed001);
        if (transform.localScale.y > maxScale) growSwitch = true;
    Debug.Log("Start of Growth");
}
 
function Shrink(){
    transform.localScale -= Vector3(2+speed001,2+speed001,2+speed001);
        if (transform.localScale.y < minScale) growSwitch = false;
}
 
function BiggerSmaller(){
 
        while(loopHandle) {
 
           if(!growSwitch) Grow();
           else Shrink();
               yield;
    }
}

If anyone has any suggestions as to how to make this code more efficient, or if I didn’t what I’m trying to do clearly enough (its known to happen…often), please let me know. Please and thank you.

You could probably achieve something with just using Physics.OverlapSphere. Maybe you don’t need to test every frame but actually once every x frames. If you still want “smooth” feedback you could sample ahead of time and wait with the response until the wave actually approach the objects.

If you still insist on scaling your object, at least make sure to use a kinematic rigid body or you will hit a lot of performance penalties due to the collision data being re baked every frame.