toggle useGravity, basic problem

I don’t understand how to toggle useGravity function on Rigidbody that is attached on the player?

I have script attached on player and I don’t know how to “talk to” Rigidbody that is attached on that player.
I was searching in the help file but I can’t get it…

if (Input.GetKeyDown (KeyCode.Space)  jump == false)
{
	jump = true;
	Rigidbody test = gameObject.GetComponent(Rigidbody);
	test.useGravity = false;
}
if (jump == true)
{
	Jpos1 = transform.position.y;
	if (Jpos1+JHeight > transform.position.y) transform.Translate(Vector3.up * MSpeed * Time.deltaTime, Space.World);
	else 
	{
		jump = false;
		transform.attachedRigidbody.useGravity = true;
	}
}

as you can see I tried these two ways of doing it, but they don’t work:

Rigidbody test = gameObject.GetComponent(Rigidbody);
	test.useGravity = false;

and

transform.attachedRigidbody.useGravity = true;

what should I write to ‘talk to’ useGravity?

and don’t ask me why is this code for jumping when jumping script exists in unity.

usually the easiest way to access a rigidbody on a gameobject is to just do: rigidbody.useGravity = false;

All Component-derived classes (MonoBehaviour is one) have a ‘shortcut’ to frequently accessed components, like rigidbodies. Just make sure there actually is a rigidbody attached, lest you get a NullRef exception.

Cheers

Don’t know if this will help but you can call it this way,

Rigidbody rb = gameObject.GetComponent<Rigidbody>();
rb.useGravity = false;

Another way is to make a private variable that stores your rigidbody information such as,

private Rigidbody myRigidbody;

    void Start()
    {
        myRigidbody = gameObject.GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space)  jump == false)
        {
            myRigidbody.useGravity = false;
        }
    }