Passing a boolean between scripts

var projectile : Rigidbody;
var boss : GameObject;
var player : GameObject;

//function Start() {
 // player = GameObject.Find("First Person Controller");
 // if (player.GetComponent(Pickup).abc())
	//Debug.Log ("pickup is true!");
//}





function OnGUI () {
	// Make a background box

		if (!boss) {
			GUI.Box (Rect (100,100,Screen.width,90), "Game Complete! You killed Gods chief angel and took over heaven!");
	}
}

function Update () {
// left click was pressed, launch a projectile
if (Input.GetMouseButtonDown(0)) {
// Instantiate the projectile at the position and rotation of this transform
var clonez : Rigidbody;
clonez = Instantiate(projectile, transform.position, transform.rotation);
// Give the cloned object an initial velocity along the current
// object's Z axis
clonez.velocity = transform.TransformDirection (Vector3.forward * 20);

   if (GameObject.Find("First Person Controller").GetComponent<Pickup>().pickedup)
	Debug.log("pick");
}
	}

Above is the code for the script that needs to access the boolean from another script.

I want it to check if a boolean from another script is true or not

public function abc() {
	return pickedup;
}

public var pickedup = false;

	function OnControllerColliderHit (hit : ControllerColliderHit) {
		if (hit.gameObject.tag == "spear") {
		Debug.Log("hit");
		Destroy(hit.gameObject);
		Debug.Log("destroyed");
			pickedup = true;
		Debug.Log("pickedup = true");
	}
}

That’s both of the scripts

Any help would be greatly appreciated!

How about declaring the pickedup variable as static and then accessing it from the other script using the name of the script where the variable is declared and then adding the variable name to the end. This altogether would look something like this:

//Add this to the second script you posted
static var pickedup : boolean = false;

//Add this to the first script
if(SecondScriptName.pickedup == true)
{
//do something
}

You will have to replace “SecondScriptName” with the actual name of that script :slight_smile:

Use a static variable.

static var Test = false;

and then in your other script you want the variable to be called from…

<name of file with boolean variable>.Test = true;

A good approach is @merry_christmas’ one. Another approach is to mantain your variables and use this syntax:

GameObject.find("object_name").GetComponent("script_name").variable_name

In your case, if I understood well, object_name is player and variable_name is pickup.