Simple Button System

hi…
I want to make a simple button system like this : when I pressed(key get up) space make it true. when I pressed(key get up again) again , make it false… and so on… like every on/off buttons. but I can’t make it… this is my script and it won’t work… what should I do?

using UnityEngine;
using System.Collections;
public class Moving : MonoBehaviour {

    public bool but = true;

void Update()
{
        if (Input.GetButtonUp("Space") && but == true)
        {
            but = false;

        }
        if (Input.GetButtonUp("Space") && but == false)
        {
            but = true;
        }
    }
    }

You set “but” to false, then immediately set it back to true right below that. You can use “else if” instead of “if”, but it would be simpler just to do

if (Input.GetKeyUp(KeyCode.Space)) {
    but = !but;
}

The point of the Button functions is that they are virtual, for things like “Fire”, “Forward”, etc., and can be changed by the user (when running standalones), and aren’t limited to keyboard keys. If you’re using a specific named keyboard key, then use GetKey.