help ..get variable value from another scirpt

Maybe this can seems a very little question but i really read all related documentation and tried several solution offeres in other thread but sincerly i cannot figured how to do that…

my problem is

I have two script:
FirstPersonController.cs
Player,cs (my main script)

i want to get a variable from FirstPersonController.cs, named “m_onladder” (relatedto my ladder script function)

variable is

public bool m_onLadder = false;

can please someone tell me the exact code i have to write to accomplish my needs??

many thaks in advance

leon

So you will need to do a few things here. First, call the FirstPersonController.cs from your Player.cs. This is done by doing something along the lines of:

FirstPersonController FPSScript;

Put this somewhere at the top of your script where your other variables are. This allows you to call EVERY public void/function from the FirstPersonController script. Remember, you can only call public scripts from other scripts with this.

From there, you can do something like:

if(FPSScript.m_onLadder == false)
{
// do things
}

If you want to call something from another script you must put the called variable name, in this case “FPSScript” before whatever you want to do with things from that script.

Hope this helped :slight_smile:

nope

i added to my Player.cs this line at the top

 FirstPersonController FPSScript;

set the m_onladder bool to “public” in the FirstPersonController.cs script

and after in the Player.cs script in the private void Update() added

if (FPSScript.m_onLadder == true)
        {
            fallDistance = 0f;
        }

fallDistance is a public float(in mi Player.cs) that i want to disable when m_onladder is true
game compile fine but when i launch the test game i have this error

NullReferenceException: Object reference not set to an instance of an object
Player.Start () (at Assets/MyScripts/Player.cs:124)

related to this line of code

 if (FPSScript.m_onLadder == true)