Please Help!!!How do I increase the speed of spawned objects using the score?

I am creating a simple catch game. I have followed the tutorials from the live session archives. My game works just fine as is. I would like to make it a little more challenging though. I would like to increase the speed at which my objects spawn, say, increasing the rate at which the objects spawn every ten points. My main problem is that my score is an int and I only want to change the speed by 9/100ths (0.09) of a second.

The code (C#) I am using to spawn is:

IEnumerator Spawn (){

yield return new WaitForSeconds (2.0f);

while (Destroyer.Score <= 9) {

Vector3 spawnPosition = new Vector3 (Random.Range (-maxWidth, maxWidth), transform.position.y, 0.0f);

Quaternion spawnRotation = Quaternion.identity;

Instantiate (object, spawnPosition, spawnRotation);

yield return new WaitForSeconds (Random.Range (1.95f, 2.0f));

	}

I have tried repeating this code over and over, just changing the range at which the objects spawn (i.e. changing 1.95f, 2.0f to 1.0f, 1.5f), this seemed to work after repeating the code several times, but then I would get an error. It also just seemed like too much repetitive code. There has to be an easier way to accomplish this. Any help would be greatly appreciated, thank you.

You can use the Random.Range(number, Score) to get more time between the numbers you are randomizing.

But i high recomend you to use a variable that will get a float deltaTime in Update function and always this variable got more value than your score the object spawns, instead using StartCoroutine every new number hit.

I wound up just speeding the spawn rate every time an object was spawned, and it works great. Here is my final script:

using UnityEngine;
using System.Collections;

public class GameMaster : MonoBehaviour {
	
	public Camera cam;
	public GameObject item;
	private float maxWidth;
	public static float speed;
	public static float difficulty;

	// Use this for initialization
	void Start () {

		if (cam == null) {
			cam = Camera.main;
		}

		speed = difficulty;
		
		Vector3 upperCorner = new Vector3 (Screen.width, Screen.height, 0.0f);
		Vector3 targetWidth = cam.ScreenToWorldPoint (upperCorner);
		float itemWidth = item.renderer.bounds.extents.x;
		maxWidth = targetWidth.x - itemWidth;
		StartCoroutine (Spawn ());
	}
	IEnumerator Spawn (){
		yield return new WaitForSeconds (2.0f);
		while (speed > 0.25) {
			Vector3 spawnPosition = new Vector3 (Random.Range (-maxWidth, maxWidth), transform.position.y, 0.0f);
			Quaternion spawnRotation = Quaternion.identity;
			Instantiate (item, spawnPosition, spawnRotation);
			yield return new WaitForSeconds (speed);
			speed -= 0.01f;
		}

			while (speed <= 0.25) {
				Vector3 spawnPosition = new Vector3 (Random.Range (-maxWidth, maxWidth), transform.position.y, 0.0f);
				Quaternion spawnRotation = Quaternion.identity;
				Instantiate (item, spawnPosition, spawnRotation);
				yield return new WaitForSeconds (0.25f);

		}
	}
}

This way, every time an object spawns, the spawn rate goes up by 1/100th (0.01) of a second. The last part of the code doesn’t allow the spawn rate to go bellow 1/4 (0.25). this way I get four objects spawning per second. This is for a 2D catch game.