Hi, I'm very new to C#, but I haven't found any information on the internet on how to do this, so I looked to a forum.
This is my script at the moment;
I'm trying to reduce the gravity by half as long as the "C" key is held down, but it isn't working. I realize that rb.gravityScale *= 0.5f might be multiplying the value instead? Is there any way to specifically set it to a number, because if I remove the * symbol the script becomes invalid. I would also like for gravity to revert back to normal as soon as the "C" key is no longer held.
Thanks.
This is my script at the moment;
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class useGlider : MonoBehaviour {
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
if(Input.GetKey(KeyCode.C))
{
rb.gravityScale *= 0.5f;
}
}
I'm trying to reduce the gravity by half as long as the "C" key is held down, but it isn't working. I realize that rb.gravityScale *= 0.5f might be multiplying the value instead? Is there any way to specifically set it to a number, because if I remove the * symbol the script becomes invalid. I would also like for gravity to revert back to normal as soon as the "C" key is no longer held.
Thanks.
Last edited by a moderator: