Increasing a random InvokeRepeating

I’m making a game where the player character moves toward the right constantly. i have obstacles and coins being spawned in the players path using

InvokeRepeating(spawn,0,random.range(#,#)).

the problem is that it picks a number and wont let me change that number during the game. i thought if i put it as “InvokeRepeating(spawn,0,(random.range(#,#) + spawnRate)” it would change when i changed the spawnRate.

Is there a way to do this without rewriting the whole thing?

I assume by # you mean an actual number, and by actual number, I mean a floating-point number. As long as those two numbers are different, it should pick a new number each time. Assuming this is in an Update function, not Start or Awake. Which is what I’m guessing you did.

Replace InvokeRepeating in Start with Invoke in Update, putting your random value there.

Actually, you probably should use a ‘timer’. Something like:

var timeBetween : float;
var lastTime = 0.0;

function Start()
{
  timeBetween = Random.value;
}

function Update()
{
  // check to see if random time has elapsed
  if ((Time.time - lastTime) < timeBetween)
  {
    // it has, get a new random time
    lastTime = Time.time;
    timeBetween = Random.Range (1.0, 2.0); // for example
    // spawn the item
    Spawn();
  }
}