RaycastHit with static variables?

I’m working on my RTS thing, and I’m totally new to ray casting. I have multiple unit selection working, but for some reason, I can’t get single unit selection working. I can get the transform by the RaycastHit (I know because I did a print(hit.transform.name and it worked fine)) but for some reason, my code isn’t able to change the static variable to be true or false.

Here is the pertinent Camera code:

var tmpHit:RaycastHit;
var ray = Camera.main.ScreenPointToRay(new Vector3(mouse.x, mouse.y)); 
Physics.Raycast(ray,tmpHit);
var script:allunits = tmpHit.transform.GetComponent("allunits");
script.Select();

and here is the allunits code:

static var selected:boolean = false;

function Update () 
{
	if(RTScamera.clicking)
	{
		//Multiple Select code
		selected = RTScamera.isBetween(RTScamera.tl,RTScamera.br,new Vector2(transform.position.x, transform.position.z));
		transform.Find("selected").renderer.enabled = selected;
	}
}

static function Deselect():void
{
	selected = false;
}

static function Select():void
{
	selected = true;
}

static function isSelected():boolean
{
	return selected;
}

EDIT:
Oh, and I know that if I named each object a different name then it would be a little easier, but I think it’d be more complex later down the line as instantiating units from buildings will be required.

changed :

var ray = Camera.main.ScreenPointToRay(new Vector3(mouse.x, mouse.y));

to :

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);

also I didn’t exactly understand what u want to do by casting ray…

I have a vector2 variable called mouse that is the mouse inputs… just to simplify my life.

For some reason some of my raycast code wouldn’t work unless I made it a vector3 like that… Don’t know why, but either way.

Pretty much I’m wanting to either run a function that is in a script or change a static variable in that script. That script being attached the gameobject hit by the raycast.

The problem is, is that it’s seeing all of the gameobject scripts as one script… I think.

To simplify my main goal is to run a function on the gameobject I just clicked on.

If I can do that, I’ll be happy, cause everything else I need for this little project, I should be able to do.

That’s how statics work. Search the forums there’s tons of discussion about it.