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.
Edit → Project Settings → Player → Resolution and Presentation → Resolution
Here check “Run in Background”.