Rotating gravity 90 degrees

Hi there! I’m very new to Unity and just learning about what this piece of software can do, so please bear with me.

I’m trying to make a game where one of the controls is rotating the player’s gravity 90 degrees each time. After looking through Google, there seems to be people recommending that you either use Unity’s built-in gravity system, or make your own. I chose to go with the former and came up with this.

using UnityEngine;
using System.Collections;

public class PlayerGravity : MonoBehaviour {

	private int gravityState = 0;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		if (Input.GetButtonDown ("c")) {
			Debug.Log ("asldjf");
			if (gravityState == 0) {
				Physics.gravity = new Vector3(-1, 0, 0);
			if (gravityState == 1) {
				Physics.gravity = new Vector3(0, 1, 0);
			if (gravityState == 2) {
				Physics.gravity = new Vector3(1, 0, 0);
			if (gravityState == 3) {
				Physics.gravity = new Vector3(0, -1, 0);
				gravityState = 0;

I did add the RigidBody component to the player so that it would be affected by this built-in gravity system, but for some reason, when I press c, my creative message “asldjf” doesn’t show up on the console, so I’m guessing that Unity is not actually reading my input. How do I go about with this? And is this code actually doing what I want it to do in terms of actually rotating gravity and affecting the player? Thanks!

You’re close!

GetButtonDown expects the name of a virtual button, which you’d find or create in your input settings.

You probably want GetKeyDown, which expects the name of a physical key on your keyboard.