Some accessing variables issues using three scripts. Please help me :)

Hi,

I’ve got some problems accessing another scripts variables. Wonder if anyone can help me out, so I post here :slight_smile:

I have three scripts : A, B , and C.

I load script A, and in script A I change a variable in script B using my own function AccessScriptB, and it works.
The problem comes out when I try to change another variable in script B when I call function X in script C using script A. No issue when I build the project, but when the function AccessScriptB in Script A is loaded it hangs.

FYI:
I can just remove my function X from script C to script A and it worked, but I want to acces it in script C for future preparation. anyone has ideas to solve this? please help me out guys…I’m still new to programming. :slight_smile:

Here’s some scripts from script A

 function AccessScriptB() {
     if( touchWithinRange  scriptB.heroTrue == false)
 {
 scriptB.heroTrue = true;
 scriptB.heroImage = heroImage1;
         scriptC.X();
        }
 }

Script C function is

 function X() { scriptB.hNU = hN;}

the function X only has that line of command since I want to change it from script C for future update preparation

touchWithinRange is a range Selection Box

hNU is a static var in Script B

heroTrue is static var in ScriptB

hN is a static var in Script C

while in script B I only shows the variables in OnGUI function

 function OnGUI()
 {
GUI.Label ( myRectValues, hNU, mySkin.customStyles[1] ) ;
}

that’s all I want to do, changing a variable in script B accessing from script A which calls the function in script C and displays it. Anyone can help me?

Hi beco13,

What actually happens when the script ‘hangs’? does it throw any errors at all in the console?

How are you linking your scripts? Variables declared at the top and assigned in the editor?

if scriptC is in the same gameObject as scriptA …
you can use getComponent(“scriptC”) instead

unless you wan to change the current function to static
like static function X() that should work too but you must use all static var in the function which is not gd