Instantiating an object with an altered gravity scale.

I’ve read more than 10 questions exactly like this one and have tried all the solutions but I’m still getting errors.

I want to instantiate an object and give it a gravity scale of 0. Here is the code (C#):

(If button press…)

Rigidbody2D temporary;
temporary = Instantiate (GameObject.Find ("wood1x1"), new Vector2 (1, 1), Quaternion.identity) as Rigidbody2D;
temporary.gravityScale = 0;

What is actually happening is the object will instantiate, but the gravity scale won’t be set and I get “Object reference not set to an instance of an object” error in console. I feel like this should be a really easy fix, but I’m not seeing it. Any help would be great.

Try this.

GameObject temporary = Instantiate (GameObject.Find ("wood1x1"), new Vector2 (1.0f, 1.0f), Quaternion.identity) as GameObject;
temporary.rigidbody2D.gravityScale = 0.0f;