How can I make script work in editor ?

i have this script
and i use to move box On Grid but he work only when i Press the button play

Is there a way to make it work in editor

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gridobj : MonoBehaviour
    public GameObject target;
    public GameObject structure;
    Vector3 truepos;
    public float gridsize;

    private void LateUpdate()
        truepos.x = Mathf.Floor(target.transform.position.x / gridsize) * gridsize;
        truepos.y = Mathf.Floor(target.transform.position.y / gridsize) * gridsize;
        truepos.z = Mathf.Floor(target.transform.position.z / gridsize) * gridsize;
        structure.transform.position = truepos;


thank you

you can use [ExecuteInEditMode]
API LINK Unity - Scripting API: ExecuteInEditMode

Even rudylee94 already answered the actual question i’d like to mention that Unity already has a snap to grid feature build in. (also see this official tip video which also mentions the vertex snapping feature)