Yes I know there are lot’s of questions about this, but when I try to get them to work they give me errors when I use the most common way: Rigidbody.useGravity or Rigidbody2D.useGravity. It says that rigidbody or rigidbody2D doesn’t contain a definition of useGravity. So how can I disable my gravity then? Is there a way to change the location of the gravity from rigidbody2D to my character script? Like a bool or something.
GameObject.GetComponent().useGravity = false;
Use reference on rigidbody:
//For rigidbody
this.rigidbody.useGravity = false;
//For rigidbody2D
this.rigidbody2D.gravityScale = 0.0f;
I hope than it will help you
There is a new answer, and it is not documented in the Scripting API:
Turning off gravity from script.
This is what the Scripting documentation tells you to do:
gameObject.rigidbody.useGravity = false;
This is the error message you get when you do that:
Assets/Scripts/ReceiveTaps.cs(59,14): error CS0619:
UnityEngine.GameObject.rigidbody' is obsolete:
Property rigidbody has been deprecated.
Use GetComponent() instead. (UnityUpgradable)’
And this is how it works:
gameObject.GetComponent ().useGravity = false;
bruh you don’t know me but i’ve been stuck trying to make an object drop on another object’s destruction for a month now (I’m new, in the unity tutorials) and with your answer i was finally able to do it. Thank you soooooo much.