Script no running issue

any facing that script is not running when Unity Editor is not active or on foreground?

I assume you mean that your game technically freezes when in background.

By default, the Application pauses when not in focus.
Go to:

EditProject SettingsPlayerResolution and PresentationResolution

Here check “Run in Background”.