Scoring not working

My ball hits the right wall it gives the point to player 2 and if it hits the left wall it also give the point to player 2.

This is the code for it:

#pragma strict

static var playerScore01 : int = 0;
static var playerScore02 : int = 0;

var theSkin : GUISkin;

static function Score (wallName : String) {
	if (wallName == "rightWall")
	{
		playerScore01 += 1;
	}
	else {
		playerScore02 += 1;
	}
	Debug.Log("Player Score 1 is " + playerScore01);
	Debug.Log("Player Score 2 is " + playerScore02);
}

function OnGUI () {
	GUI.skin = theSkin;
	GUI.Label (new Rect (Screen.width/2-150-12, 25, 100, 100), "" + playerScore01);
	GUI.Label (new Rect (Screen.width/2+150-12, 25, 100, 100), "" + playerScore02);
}

Try using two if statements instead of a single if/else.

Also, sorry for the stupid question but have you checked to make sure the walls have the correct names?

The variable names do not equal the object name.

What you are doing is trying to compare the object name of the collided wall with a string version of the variable name, not with what the wall is actually called.

I mean, I highly doubt the walls in your object hierarchy are called “rightWall” and “leftWall”, right?

In your object hierarchy, call your walls something like “Left Wall” and “Right Wall” if you haven’t already, then change your if/else statement to this:

if(wallName == "Right Wall")
{
    playerScore01 += 1;
}
else if (wallName == "Left Wall")
{
    playerScore02 += 1;
}