How do you change gravity with a press of a button? Unity 2D

I want my player to be able to change gravity when I press the space bar… kinda like in this game www.worigame.com is a custom short domain

Is there any code I can use… and any other tips so that my game can be as similar as that one.

Sorry it the question is kind of confusing, english is not my first language

For this, Physics2D.gravity is your friend.

To give an example of a simple implementation to start from, you could try something like this:

// C#

void Update()
{
	if(Input.GetKeyDown(KeyCode.Space))
	{
		Physics2D.gravity *= -1;
	}
}

With this bit implemented into a script, gravity will reverse by pressing spacebar (by multiplying by -1).

Thanks! I ended up doing using this code in case anyone needs it, thanks again :smiley:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update()
	{
		if(Input.GetKeyDown(KeyCode.Space))
		{
			Physics2D.gravity *= -1;
		}
	}
}