Problem About Gaining Points

Hello everyone, i have 107 golds in my scene and we need to collect them, i wrote a code but it takes the first one, but it doesn’t take the second one, what can be the problem ?

Here it’s :

var distance = 100;
var gold : Transform;
var blipsound : GameObject;
var gold2 : Transform;






function Update ()
{

GameObject.Find("g_Points").guiText.text = ""+PointCode.points;

if(Vector3.Distance(transform.position,gold.position) < distance)
{
    GainPoints();
   }
else if (Vector3.Distance(transform.position,gold2.position) < distance)
{
   
   GainPoints();
  }
  }
  
  function GainPoints()
  {
    Destroy(gold.gameObject);
	PointCode.points+= 5;
	blipsound.audio.Play();
  }

what should i do ? If there was 10 or 15 golds, i could put 15 different scripts which are specific for each gold . But there are 107 golds, so when i did it the FPS reduces to 2 , any suggestions to make that script work?

Basically, what you are doing is hard coding the distance check for all of the gold objects, drastically reducing flexibility. There is one good way to do what you want to do, and it is pretty simple.

First, you need to add a BoundingSphere to your gold prefab (Components->Physics->Bounding Sphere), set the sphere to the size you want, and check is trigger on the sphere. Then, add a new behavior to the gold object. The behavior should contain the following:

function OnTriggerEnter(coll : Collider)
{
    blipsound.audio.Play();
    PointCode.points+= 5;
    Destroy(gameObject);
}