Component.GetComponent question

I’m not exactly new to Unity anymore, but I’m still struggling to grasp accessing other scripts through code.

In my most recent game, i’m trying to access a boolean from another script which says whether an object has triggered collider or not.

However I have 2 problems…

alt text

I’ve inserted * around the problem lines of code for easier understanding.

FallingblockcolliderScript:

*var collidertouch : boolean;*

function Start () {
	collidertouch = false;
}

function OnTriggerEnter(otherObject: Collider){
  	if(otherObject.gameObject.tag == "Player"){
	collidertouch = true;
	}
}

FallingblockScript

function Start(){
    	wallhit = true;
    	var someScript : FallingblockcolliderScript;
    	someScript = GetComponent (FallingblockcolliderScript);
    	someScript.collidertouch ();
    }

function Update () {
	if (wallhit == false){
		fall();
	}
	*if (someScript.collidertouch == true){*
		rise();
		}
}

Yep, It’s probably obvious, but if I dont ask I’ll never learn

The thing is you can’t just get a script without any reference. Tell unity which object that script attach to. Like the link that asafsitner post.

i.e

 someScript = gameObject.GetComponent ("FallingblockcolliderScript");

This is just example. It might not work because I don’t know which object has that component.

Well, in coding, there’s always an alternative way. You can also use static var so that other script can access it easily.

FallingblockcolliderScript:

static var collidertouch : boolean;

FallingblockScript:

if (FallingblockcolliderScript.collidertouch == true){
       rise();
    }

Hope this helps! Good Luck!