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.