I’m very new to coding and unity2d as a whole. I am trying to make my character glide if the player is holding down space by lowering the gravity. So how would I change the gravity back after lowering it? Thanks!
public class Glide : MonoBehaviour
{
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
rb.gravityScale = 2;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.gravityScale = 1;
} else if (rb.gravityScale != 2);
{
rb.gravityScale = 2;
}
}
}