I am making a timer in editor window, But the timer work weird

sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ExampleWindow : EditorWindow
{
    float timeStart;
    bool str;

    [MenuItem("Window/Timer")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow<ExampleWindow>("Timer");
    }

    void Start()
    {
        timeStart = 0;
        str = false;
    }

    void Update()
    {
        if (str)
        {
            timeStart += Time.deltaTime;
        }
    }

    void OnGUI()
    {
        GUILayout.Label("This is a Timer.", EditorStyles.boldLabel);
        
        if (GUI.Button(new Rect(10, 40, 60, 30), "Play"))
        {
            str = true;
        }
        if (GUI.Button(new Rect(70, 40, 60, 30), "Pause"))
        {
            str = false;
        }

        if (GUI.Button(new Rect(130, 40, 60, 30), "Restart"))
        {
            str = false;
            timeStart = 0;
        }
        EditorGUILayout.LabelField("Time Count", timeStart.ToString());
    }


}

It appears that the code you provided is for a Unity editor window, not a game object in the scene. In Unity, the Update function is used to perform actions on game objects in the scene, while the OnGUI function is used to draw GUI elements in the editor window.

In this code, the timeStart variable is being incremented in the Update function, but this function is never called in the editor window because it’s not attached to a game object. As a result, the timer does not work as expected.

To fix this, you can move the code that increments timeStart from the Update function to the OnGUI function. This will ensure that the timer is updated whenever the GUI is drawn. You can also remove the Start function, as it is not being used.

Here is an example of how your code could be modified to fix the timer:

using UnityEngine;
using UnityEditor;

public class ExampleWindow : EditorWindow
{
    float timeStart;
    bool str;

    [MenuItem("Window/Timer")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow<ExampleWindow>("Timer");
    }

    void OnGUI()
    {
        GUILayout.Label("This is a Timer.", EditorStyles.boldLabel);

        // Update timeStart in the OnGUI function
        if (str)
        {
            timeStart += Time.deltaTime;
        }

        if (GUI.Button(new Rect(10, 40, 60, 30), "Play"))
        {
            str = true;
        }
        if (GUI.Button(new Rect(70, 40, 60, 30), "Pause"))
        {
            str = false;
        }

        if (GUI.Button(new Rect(130, 40, 60, 30), "Restart"))
        {
            str = false;
            timeStart =