If you post code snippets mark it as code. Just highlight the code and press the "101010" button. Also format the code in a common way so others can read it.
Yes - although this was answered back in 2011, it’s still high in Google results for “unity change gravity”. The code posted above by Justin is incorrect and not required - the code from Bunny83 is the correct code to be using. Physics.gravity only needs to be set once to make the change for all objects in the current scene.
It's because the OP (and Bunny83's correct response) was written UnityScript. You're probably using C#, like most people, and so yes you want Physics.gravity = new Vector3(x, x, x); Or just do Physics.gravity = Physics.gravity * -1; // invert existing gravity
You may have to do your gravity manipulation (see Bunny83’s answer) in the “LateUpdate()” method.
I was trying it in other methods in my mobile game and it was acting weird and not changing right away. Tonight I tried doing the "Physics.gravity = " statement in “LateUpdate()” and that works perfectly.
What I do is in my other methods, when I know I want gravity changed, I set a boolean variable to True. Then in “LateUpdate()” I check that bool, and if it’s true, do the manipulation, then set it to False.
If you post code snippets mark it as code. Just highlight the code and press the "101010" button. Also format the code in a common way so others can read it.
– Bunny83