How do i make a pause button?

I’m making a game where you roam around and kill monsters and i don’t know how to make a game pause button

Have you made a button that does nothing yet?

Once you’ve done that, make a script that has a public function that sets Time.timeScale to 0 and place it on a game object.

Once you have that, make the button call the function on your script.

A video on how to setup and use buttons.

If you don’t want your button to get input (such as spacebar) after clicking on button, you must deselect it. Here’s a script that you can add to the button to deselect it on click, so that space bar no longer will click the button for you.

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

[ExecuteInEditMode]
public class DeselectOnClick : MonoBehaviour
{
    public Button button;

    void Awake()
    {
        if (!button)
            button = GetComponent<Button>();
    }

    void OnEnable()
    {
        if (button)
            button.onClick.AddListener(Deselect);
    }

    void OnDisable()
    {
        if (button)
            button.onClick.RemoveListener(Deselect);
    }

    void Deselect()
    {
        if (EventSystem.current)
            EventSystem.current.SetSelectedGameObject(null);
    }
}