How to use 'check if player is on ground' bool in script

Hi, I’m trying to integrate a bool into a controller script, but I cannot get it to work. The section of the script I’m working with:

void FixedUpdate()
{
	//here are actions where the buttons can be held for a longer period
	if (mPlayer && mHasControl)
	{
		if (Input.GetButton("Jump"))
			mPlayer.Jump();

		mPlayer.Walk(Input.GetAxisRaw("Horizontal"));
	}
}

I want to add a bool that is defined in another script:

bool mOnGround = false;	//Are we on the ground or not?

So I’m trying to get the line to read:

if (mPlayer && mHasControl && mOnGround)

What’s the right way to do this? The reason I’m doing this is because when I jump without moving forward, and then in the air hit the move key… the walk animation plays instead of finishing the jump animation, which is very weird!

Thanks!

var pp : PlatformerPhysics = GetComponent.<PlatformerPhysics();

if (pp.mOnGround .....

or

PlatformPhysics pp = GetComponent<PlatformPhysics>();

Sounds like you have the 2 scrips on the same object, and so rightfully expect to access it. However you are missing the scope!

You need to use GetComponent in the local context.

Lets say you have two scripts _A and _B attached to the same object.
_A has the variables if mPlayer, mHasControl.
_B has the variable mOnGround.

Inside A, to get access to script _B, you need to call the component _B. As it is sitting on the same game object as _A, you should be able to simply type

gameObject.GetComponent<_B>().mOnGround; 

This can extend to a further script C:

Say object_one has scripts _A and _B
object_two has script _C

_C can access _A or _B by simply :

public GameObject some_object; // attach obejct_one via editor
private bool mOnGround;
        
void Start()
{
    mOnGround = some_object.GetComponent<_A>(). mOnGround;
}

I hope this helps!