Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do i change gravity in code?

Discussion in '2D' started by FalsAlarm, Dec 25, 2016.

Thread Status:
Not open for further replies.
  1. FalsAlarm

    FalsAlarm

    Joined:
    Dec 12, 2016
    Posts:
    21
    i tried the following code but it doen't work.

    Code (CSharp):
    1. UnityEngine.Physics.gravity = new Vector3(-10,0,0);
     
  2. FalsAlarm

    FalsAlarm

    Joined:
    Dec 12, 2016
    Posts:
    21
    I just figured out the problem. My game is a 2d game so I had to use the below code to get it to work.

    Code (CSharp):
    1. Physics2D.gravity = new Vector3(-10f,0f,0f);
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Don't cross post please.
     
Thread Status:
Not open for further replies.