Passing variables from one script to another

The situation is next:
i’ve got two different scripts on two different objects with one boolean var in each. So i want to pass those vars to the third object’s script. I’ve searched the Script Reference but i didnt managed to solve it. Thanks for any clues.

First you need a reference to the object, then a reference to the script. More info here:

http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

EDIT: Link fixed

ok i’ve done it this way:

var target : electrocell2;

function Update () {
var object = GameObject.Find("electroCell2");
var value = object.GetComponent(electrocell2).op2; 


if (target.op2 == true){
 particleEmitter.emit = true;
 }
 if (target.op2 == false){
particleEmitter.emit = false;
}
}

this script is placed on a particle emmiter and it takes a var “op2” from GO “electroCell2”
It works just perfect!
But… as i mentioned before i need 2 var from 2 objects, so i did this :

var target : electrocell2;
var target : electroCell1;

function Update () {
// Set variable of the target object
var object = GameObject.Find("electroCell2");
var value = object.GetComponent(electrocell2).op2; 

var object = GameObject.Find("electroCell1");
var value = object.GetComponent(electrocell2).opened; 

if ((target.op2 == true)(target.opened == true)){
 particleEmitter.emit = true;
 }
 if (target.op2 == false){
particleEmitter.emit = false;
}
}

And i’m receiving this error…:
Assets/My Scripts/particleEmit1.js(2,14): BCE0018: The name ‘electroCell1’ does not denote a valid type.

ok corrected a bit :

var target : electrocell2;
var target : electrocell1;

function Update () {
var object = GameObject.Find("electroCell2");
var value = object.GetComponent(electrocell2).op2;

var object = GameObject.Find("electroCell1");
var value = object.GetComponent(electrocell1).opened;

if ((target.op2 == true)(target.opened == true)){
 particleEmitter.emit = true;
 }
 if (target.op2 == false){
particleEmitter.emit = false;
}
}

Now the problem is
“Type ‘particleEmit1’(script name) already has a definition for ‘target’.” As i understand there can be only one “target” in a script…
So is there a way to pass to vars from to scripts to the third script???

target is just a variable, and you can have as many variables as you want, but they all have to have different names.

More info here:

http://forum.unity3d.com/viewtopic.php?t=36096

OMG :sweat_smile: how could i say smthing like that… It may be cuz of sleepless night
Thanx…

FYI, you’ve got a lot of redundant code you don’t need.

Just do this:

private var otherScript : yourScriptName;

function Awake(){ 
	otherScript = GameObject.Find("yourObjectName").GetComponent(yourScriptName); 
}

function Start(){
	otherScript.yourVariableName = true;	
}