get var from tagged object by using the tag

yo guys - is there a possibilty to use tags and getcomponent at the same time?
what i what to do is get a variable from a script by using a tag. in this case: get the var “isChasing” from “EnemyAI.js” wich is added to the object wich is tagged with “Enemy”…

function Update () 
{			
var getScriptFrom: GameObject[];
	getScriptFrom = GameObject.FindGameObjectsWithTag("Enemy");
	var getScript:GameObject = getScriptFrom[0];
	getScript = GetComponent("EnemyAI");//works not
	
	
	var LookAtTarget : GameObject[];
	LookAtTarget = GameObject.FindGameObjectsWithTag("Player");
	var thePlayer:GameObject = LookAtTarget[0];//works


		if (EnemyAI.isChasing)
		{........and on....

i don´t know why it´s not working… :confused:

i know it´s possible to set “isChasing” to a static var, but that´s not what i need.

This should work:

private var go : GameObject;
private var script : myScript; //change myScript to your script name

function Awake(){
	go = GameObject.FindGameObjectsWithTag("Player")[0];
	script = go.GetComponent(myScript);
}

function Update(){
	script.variable = "Hello world!";
}

You could also replace FindGameObjectsWithTag(“Player”)[0] with FindWithTag(“Player”)

hmmm… it´s not working:/
wenn i start the game the debugger is bitching…

NullReferenceException: Object reference not set to an instance of an object
EnemyTurretControl.Update () (at Assets\005_Scripts\EnemyTurretControl.js:27)

private var go : GameObject;
private var script : EnemyAI; //change myScript to your script name 

function Awake()
{
   go = GameObject.FindWithTag("Player");
   script = go.GetComponent(EnemyAI);
} 
	
function Update () 
{			
	//var getScriptFrom: GameObject[];
	//getScriptFrom = GameObject.FindGameObjectsWithTag("Enemy");
	//var getScript:GameObject = getScriptFrom[1];
	//getScript = GetComponent("EnemyAI");

	var LookAtTarget : GameObject[];
	LookAtTarget = GameObject.FindGameObjectsWithTag("Player");
	var thePlayer:GameObject = LookAtTarget[0];


		if (script.isChasing)// LINE 27

go = GameObject.FindWithTag(“Player”); … :smile: ups - ths for the advice, it´s working now