How to turn off gravity?

I’m working on a top-down game in unity, which is using 2d. However, I can’t find a way to turn off gravity. Any help is much appreciated. Thanks in advance!

You can turn off gravity individually on each Rigidbody. In addition you can turn off gravity globally by:

Edit > Project Settings > Physics2D

Or in code :

Physics2D.gravity = Vector2.zero;

Try Edit > Project Settings > Physics and turn Y to 0. That’ll make the Y Gravity 0 thus turning off gravity. Not sure if that’s what you were looking for though. Hope it helps!

How to turn it on and off …

This worked for me (attached script to game object).:

public static var rigidbod : Rigidbody;

function Awake () {  // initialise the variable
    rigidbod = GetComponent(Rigidbody);
}

function Update () {
      rigidbod.useGravity = false;
       // rigidbod.useGravity = true;
}

OR:

Physics.gravity.y = 0;