Fixed Spawn Amount

Ok, so i’ve got a script which is applied to different object which tells it to spawn cubes when a particle hits the object.

So I’ve got this script:

var ThePlace : GameObject;
var hasportal : boolean;
var portalblue : GameObject [];

function newportal () {
	
	if (hasportal==false){
	
	theportal=Instantiate(portalblue[(Random.Range(0, portalblue.Length))],ThePlace.transform.position,transform.rotation);
	theportal.transform.eulerAngles.x=-90;
	theportal.transform.position.x=ThePlace.transform.position.x+1;
}
}

I want to set it up so that every one in a thousand cubes which spawn, a small cube spawns.
(portalblue is the cube, The Place is the place where they spawn, hasportal is if the particle hits the object)

I don’t want to go into each object in the Inspector and add 1 thousand elements, 999 being a cube and 1 being a small cube.

How do I set it up in this script so that I can set percentages?
Thanks

You can do it through absolute count, or you can do it through random number. For count you could have a variable that you increment each time you spawn. And then code something like:

if (iCount >= 1000)
{
    iCount = 0;
    // Do the small cube spawn.
}

For random you could do something like:

i = Random.Range(0,1000);
if (i == 0)
  // Do the small cube spawn.

The second method produce small cubes on average every 1000 spawns.