Changing character run speed based on another scripts variable

Basically i have a game that consists of 2 mini levels per level, In the first level the player drops a ball and depending on how many obstacles they hit they are awarded a score, for example "player hit 2 obstacles giving them a score of 2"

The second section on the level involves the player controlling a character from a top down view avoiding other obstacles. I would like to use the score from the previous scene to modify the speed at which the player moves (i know how to manipulate the speed but not how to access the variable from the script in the last scene)

Answers in javascript would be much appreciated.

First preference is to use "Don't Destroy on load" which keeps certain objects when a new scene loads, which means you can carry over your "Main" controller object holding the score and access it as a static variable.

DontDestroyOnLoad (gameObjectWhoIsHoldingScore);

The other more hacky way is to store it using the playerprefs in-built unity function.

PlayerPrefs.SetInt("Score", scoreVar);

then in the new scene:

SpeedModifier = PlayerPrefs.GetInt("Score");

Take your pick. I advise having a look at both in the scripting reference.

create a function that returns the variables value you need, like:

var xyz = 1;   
function returnXyz(){
    return xyz;

then it can be accessed by another script via

var _script : ScriptName;
var _script = GetComponent(ScriptName);
// some code here

(in this case both scripts would be components of the same GameObject, modify as you need)

edit: this only works if your 2 mini levels are in one scene, which i kinda thought of now =/ otherwise nvm