Scoring and Variables

Hey guys this is a 2 part so please bear with me. I’m currently creating a game that has multiple levels and as the levels go up, I want the difficulty to increase. I also wanted to maintain the score as the scene changes. So my questions are as follows

  • How can I increase the variable of a falling object to make the level more difficult as it goes up?
  • How do I keep the user’s score between levels so that in the next scene, the score doesn’t reset?

For example, what I currently have in terms of falling objects is the following:

function Start () {
	//When your object first gets created
	for (var i:int=1; i <= 1; i++) {
		InvokeRepeating("SpawnZ", 0, 0.7);
	}
}

I want the variable that increases the rate of them falling to increase so they will fall faster and make the Z’s harder to catch. I anticipate and appreciate any help that you guys can give me!

Thanks in advance,

Slyy

For keeping a score, use DontDestroyOnLoad(). This will let you keep an object between scenes, and all variables on the scripts it holds will be kept as well.

I’m not sure on the other one: do you want to change it based on which scene you’re in, or based on how long you’ve been in there, or your score, or something else?

If it’s by scene, I’d use Application.loadedLevel to check which scene number, then base it on that. Switch that 0 with a variable, then change the variable based on the scene number or whatever.