c# speed myself up when a button (string) is pressed

I want my character to speed up when I press a button that is set by a string, something like this

public class Racer : MonoBehaviour {

public float speed;
public string speedButton;

private bool spedUp

 void OnTriggerEnter(Collider other) {
if (Input.GetKeyDown(speedCheat))
            if (spedUp)
                speed = 15;
                spedUp = false;
                speed = speed + 10;
                spedUp = true;

Yes I did make rigidbody and all that stuff, my speed float works just fine. This code is the one that just doesn’t work, and I don’t know what do I need to do in order to press a button that I set by a string in my Inspector. Can someone fix this up for me?

Both the OnTriggerEnter function and the GetKeyDown function only happen in the single frame in which they became true. So, in order for your if statement to be true, the player would have to push the speedCheat key in the exact same frame that they enter the trigger.

The easiest solution I can think of, without knowing exactly what you’re trying to do, is to change GetKeyDown to GetKey. GetKey will be true as long as you’re holding down the key, so if you hold the key down while you go through the trigger, your if statement will be true.