Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // This is for changing gravity direction on the Y axis for
  2. // a particular object.
  3. // This is for Unity.
  4.  
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8.  
  9. public class CharacterMovement : MonoBehaviour {
  10. float FORCE_OF_GRAVITY = 9.8F;
  11.  
  12. void Start () {
  13. Debug.Log("Start");
  14. }
  15. void Update () {
  16. // Change gravity on mouse click
  17. if (Input.GetMouseButtonDown(0)) {
  18. if (Physics.gravity.y > 0) {
  19. // Normal gravity so downward force of -9.8
  20. Physics.gravity = new Vector3(0, FORCE_OF_GRAVITY * (-1), 0);
  21. } else {
  22. // Inverse gravity
  23. Physics.gravity = new Vector3(0, FORCE_OF_GRAVITY, 0);
  24. }
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement