one variable for all

i made some thing from one tutrial…no make lot of changes in it… and gonna make more…
now i got some problem in here…
i wanan define one wariable but for all …
please some one help me :

this give me error… and i dunno where should i fix that…

private var creationTime=Time.time;
var LifeTime=3;
var DoDamageRange=10;
var explosionPrefab:Transform;

function Awake () 
{
	creationTime=Time.time;
}

function Update()
{
	if(Time.time>creationTime+LifeTime)
	{
		Destroy(gameObject);
		
		Instantiate(explosionPrefab,transform.position,Quaternion.identity);
		//destroy around obj
		var cols = Physics.OverlapSphere(transform.position, DoDamageRange);
		for (i = 0; i < cols.Length; i++) 
		{
			if (cols[i].gameObject.tag=="turret")
			{
				GameObject.Find("GUI Text").guiText.text=""+ cols[i].GetComponent("TurretControl").TURRET_HEALTH;
				cols[i].gameObject.GetComponent("TurretControl").TURRET_HEALTH = cols[i].GetComponent("TurretControl").TURRET_HEALTH - 25;//Destroy(cols[i].gameObject);
			}
		}
	}
}

[/code]

Do you mean you want a variable to share the same value among all instances of the object (so if one object changes it, all the others see the change)? You can declare the variable static to make this happen:-

static var sharedVar: int;

The code you’ve posted does actually compile without errors. Are you getting errors when you run it or is it just not doing what you would expect?

no i want a variable reachable from any where like static…
but in each object have diff value

Why not make a static array?

Yes, i am agreed with you. For that, it is better to use static array so your code will be less. So it is the best solution for it.

andeeee - quick question on this - do I declare it as static within each of my scripts? e.g. at the top of each script - is that how it carries? I am calling the same var within different scripts (including awake in level script) and it isn’t carrying.

I did search the documentation for good examples, but I think I am missing something basic here.

Thanks for your time,
~]3