So im trying to implement a feature where you can toggle gravity on the player for a few seconds, but when i go to test it unity completely freezes and im not sure what ive done wrong. heres the code snippet private void Update() { while (Input.GetButton("Jump")) { ToggleGravity(); } } void ToggleGravity() { if (GravCharge > 0) { rb.useGravity = false; GravCharge -= (1F / GravCharge_use) * Time.deltaTime; } else { rb.useGravity = true; } }
first of why is you Update void private? it's just void Update(){ } then I think the issue comes from your while loop, try Code (CSharp): if(input.GetKey(KeyCode.YourButton)) { }
thank you! that stopped the crashes but unfortunately now it wont turn off >.< dunno why i didnt think to change that to an if instead of while