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.


*var collidertouch : boolean;*

function Start () {
	collidertouch = false;

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


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

function Update () {
	if (wallhit == false){
	*if (someScript.collidertouch == true){*

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.


 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.


static var collidertouch : boolean;


if (FallingblockcolliderScript.collidertouch == true){

Hope this helps! Good Luck!