Rigidbody Gravity scripting question (Javascript Answers Only!)

Okay. I’m making a simple game where you simply turn gravity on and off. So my question for you is how would i turn off gravity on the rigidbody so that i can push it around (I already got the script to make it push around i only need to know how i would turn off the gravity for many models just by the push of a gui button)

“how i would turn off the gravity for
many models”

You need some unique property of the set of models you want to turn off or on. It could be a tag or a script that they or only they share. Or you could build a list as you create them. Here is a function that works with the tag ‘Pushable’:

function SetGravity(gravity : boolean) {
    var objs = GameObject.FindGameObjectsWithTag("Pushable");
    for (var obj in objs) {
        obj.rigidbody.useGravity = gravity;

function OnGUI() {
    if (GUI.Button(Rect(0,0,100,50), "Disable")) 
    if (GUI.Button(Rect(0,75,100,50), "Enable")) 

Note the above code assumes that all object tagged with ‘Pushable’ have a Rigidbody component? Also why do you have to turn off gravity in order to push something around. With gravity and friction an object is more difficult to push, but all you have to do is add more force.

I am not sure if this would halp you, but Physics.Gravity = Vector3.zero turns off gravity entirly