setting position of x-axis for gui label

i am making a game in which i am using gui label i want to set position of x axis like that when first character appears 2nd must appear a little further i am using.

var isClicked : boolean=false;
var xpos: float = 200;
var xpox:float; 
var i:float;

function Start () {}
function xchange(): float{

xpos= xpos+8;
i=xpos;
return i;

}
function OnMouseDown()
{
   isClicked = true;
}

function OnGUI()
{
   if (gameObject.name == "Sphere 1(Clone)" && isClicked ){
   xpox=xchange();
   GUI.Label(new Rect(xpox,260,400,100), "B");
}     

   else if (gameObject.name == "Sphere(Clone)" && isClicked ){
   xpox=xchange();
     GUI.Label(new Rect(xpox,260,400,100), "A");
   }
 }

in this code every time i click sphere the alphabet appears but the problem is every time the alphabet appear it start on the screen it is due to this portion of code.

function xchange(): float{
 
 xpos= xpos+8;
 i=xpos;
 return i;
 
}

I just want that every alphabet that i click must appear a little further from first one.

I’m guessing that you want to allow each object to only be clicked on once. In order to make this work, you have to somehow communicate the ongoing x position between the various objects. I’m going to use a static variable for this solution. A static variable is shared between all instances of the same class…between all the game objects that use the same script. Generally I avoid static variables because they can be a source of great pain in programming, but in this case it makes for a very simple fix for your problem. In addition, I’m going to assume that you name your game object with the letter. So instead of having a name like “Sphere(Clone)”, the name will be “A”. You can edit the names in the inspector. Attach this script to each object and make the game object name the letter you want to display:

#pragma strict

static var nextPos = 200;

var isClicked : boolean=false;
var xpos: float = 200;
 
function OnMouseDown()
{
	if (!isClicked) {
		isClicked = true;
		xpos = nextPos;
		nextPos += 8;
	}
}
 
function OnGUI()
{
	if (isClicked ){
		GUI.Label(new Rect(xpos,260,400,100), gameObject.name);
	}
}