Toggling UseGravity of Rigidbody PREFAB via script

Hey there. I have an object in my game that creates a cube. I want to toggle the cube’s gravity on and off during the game. Is there a script that can do this.

///Is there a script similar to this for a prefab

GameObject.rigidbody.useGravity = false;

I tried this script. I think it doesnt work cuz the object is a Prefab. I would greatly appreciate it if someone could help me. :slight_smile:

On the prefab set a tag, when the object is created all objects will have the same tag…
then in your script:

GameObject[] tags = GameObject.FindGameObjectsWithTag("customTag");
for (int i = 0; i < tags.Length; i++)
{
	tags*.rigidbody.useGravity = false;*

}

Im getting errors and they might be typos but idk what im doing here. Still a noob at scripting. What’s the “i” mean in all of this? By the way I forgot to mention that im using javascript if this isnt javascript already.

I guess that you instantiate the cube. So the code should look like this:

function MakeCube()
{
    var cube = Instantiate...;
    cube.rigidbody.useGravity = false;
}

– David

javascript, same as my previous post.

var tags : GameObject[] = GameObject.FindGameObjectsWithTag("customTag");
for (var i : int = 0; i < tags.Length; i++)
{
    tags*.rigidbody.useGravity = false;*
*}*
*```*