how to reference character controller by script from another object

Hi,

I am trying to reference the character controller from a script attached to another object (for example, from a script attached to a cube). It is easy to just leave the “controller” var public and drag the character controller on to it in the inspector, but I would rather reference it entirely by code – something like below, which does not work. Any suggestions? Thanks. Zaffer

 private var controller : CharacterController;
 function Start(){
	controller = gameObject.GetComponent(CharacterController);
	Debug.Log(controller);
 }

P.S. I seem to be having trouble formatting my code – using the “pre” and “code” tags which don’t seem to work very well. Any suggestions? Thanks.

I haven’t messed with character controller much at all, so there might be an even easier way of accessing that than this ; but as for accessing other scripts on a specific object you could go about it with something like this->

var player : GameObject ;
var script : ScriptName ;
 
function Start(){
   player = gameObject.FindWithTag("Player") ;
   script = player.GetComponent(ScriptName) as ScriptName ;
}
 
function Update(){
   if(Input.GetKeyDown(KeyCode.T))
      script.FunctionName() ;
      script.variableName = whateverValue ;
   }
}