Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is for changing gravity direction on the Y axis for
- // a particular object.
- // This is for Unity.
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CharacterMovement : MonoBehaviour {
- float FORCE_OF_GRAVITY = 9.8F;
- void Start () {
- Debug.Log("Start");
- }
- void Update () {
- // Change gravity on mouse click
- if (Input.GetMouseButtonDown(0)) {
- if (Physics.gravity.y > 0) {
- // Normal gravity so downward force of -9.8
- Physics.gravity = new Vector3(0, FORCE_OF_GRAVITY * (-1), 0);
- } else {
- // Inverse gravity
- Physics.gravity = new Vector3(0, FORCE_OF_GRAVITY, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement