How do I make my score go up upon a collision?

As it stands right now, I have a cube and when it is hit by a ball shot by the player, it changes green and plays a noise. I would like to make a score system that goes up with correct answers and down with incorrect answers. Please help, I’m new to Unity! Thanks

var LevelToLoad : String;
public var CorrectSound : AudioClip;
function OnCollisionEnter (Collision){
	gameObject.renderer.material.color = Color.green;
	audio.PlayOneShot(CorrectSound);
	yield WaitForSeconds (3);
	Application.LoadLevel(LevelToLoad);
};
//This code is associated with the collision box. If the ball hits it, it will play the designated sound, wait three seconds then advance to the next level.

First you need to create a variable that all scripts can be aware of.

With Javascript, you can accomplish this by marking a variable as both public and static. The public keyword makes it so that other scripts can access the variable, and the static keyword makes it so that you do not need to attach the script to a GameObject to use this variable.

// in a script called "TestScriptA.js"
public static var score : Number = 0  

Now, all another script needs to do to access this variable is to call it by the script name, use the . to show that the “TestScriptA.js” is the owner of the variable:

// in a different script called "TestScriptB.js"
function Update ()
{
    // press 'A' down to add 1 to the score
    if(Input.GetKeyDown(KeyCode.A))
    {
        TestScriptA.score++;
    }

    // press 'S' down to subtract 1 from the score
    if(Input.GetKeyDown(KeyCode.S))
    {
        TestScriptA.score--;
    }
}

Now, you need another function to show the score on the screen, if that’s what you want to do. You can either put this in “TestScriptA.js”, or in a separate script. But be aware that if you want Unity to call OnGUI(), the script does have to be attached to a GameObject:

function OnGUI()
{
    // define the size of the area that will have the text
    var rectangle : Rect = Rect(10, 10, 100, 100);
    
    // draws the text in the rectangle on the screen.
    GUI.Label(rectangle, "Score: " + TestScriptA.score);
}

I hope that helps!

Thanks, that helps a lot! What is the if statement for a collision? and also, how do I edit the size of the text? It is too small for the resolution