problem in scripting newbie code

i new help guys in this code where the gui is not right
the code not showing any errors but i have two ammo labels one ove one why?

var projectile : Rigidbody;
var speed = 20;
var ammo :int ;
function Update()

{
if(Input.GetKeyDown("e")){
ammo += 20;
}
if( Input.GetButtonDown( "Fire1" ) && ammo !=0)
{

var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
ammo --;
}
}
function OnGUI(){
GUI.Box(Rect(25,175,25,25), ammo.ToString());
}

if(Input.GetKeyDown("e")){
ammo += 20;
}

thansk in advance

Mhatem2439,

I’ve tried out your code and have it exactly as this:

var projectile : Rigidbody;
var speed = 20;
var ammo :int ;
function Update()
{
	if(Input.GetKeyDown("e"))
	{	ammo += 20;	}

	if( Input.GetButtonDown( "Fire1" ) && ammo !=0)
	{
		var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
		instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
		Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider );
		ammo --;
	}
}

function OnGUI()
{	GUI.Box(Rect(25,175,25,25), ammo.ToString());	}

And I’m not seeing any strange behaviour at all. (Also, I’ve taken out an out of place “GetKeyDown” call that added ammo, but that wasn’t causing the problem, I tested with and without)

If I understood your problem correctly, you are seeing two gui boxes that read the ammo count, is that right?
If that’s the case, then check how many objects in your scene you applied that script to, if it’s more than one, then you’ll find they each will make their own gui box to count ammo. Also, make sure that you haven’t accidentally assigned this same script twice to the same object, that will case the same problem.

Good luck