Created
January 9, 2026 06:58
-
-
Save fangzhangmnm/887a4b29bb9b377baaa1dda6c28f346f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /********** | |
| This script adds a simple Unity Editor window that allows you to control the Time.timeScale | |
| Warning: Code is blind-generated by AI without human inspection, use at your own risk. | |
| Author: chatgpt.com | |
| Supervisor: fangzhangmnm, Jan.9 2026 | |
| License: MIT | |
| **********/ | |
| #if UNITY_EDITOR | |
| using UnityEditor; | |
| using UnityEngine; | |
| /// <summary> | |
| /// Small Editor utility for controlling Time.timeScale at runtime. | |
| /// Appears in Window → Time Control. | |
| /// </summary> | |
| public class TimeScaleInspector : EditorWindow | |
| { | |
| float targetScale = 1f; | |
| bool paused; | |
| [MenuItem("Window/Time Control")] | |
| static void Init() | |
| { | |
| GetWindow<TimeScaleInspector>("Time Control"); | |
| } | |
| void OnGUI() | |
| { | |
| EditorGUILayout.LabelField("Time Control", EditorStyles.boldLabel); | |
| EditorGUILayout.Space(); | |
| // Pause toggle | |
| bool newPaused = GUILayout.Toggle(paused, "Pause Game"); | |
| if (newPaused != paused) | |
| { | |
| paused = newPaused; | |
| Time.timeScale = paused ? 0f : targetScale; | |
| } | |
| EditorGUI.BeginDisabledGroup(paused); | |
| // Time scale slider | |
| float newScale = EditorGUILayout.Slider("Time Scale", Time.timeScale, 0f, 5f); | |
| if (Mathf.Abs(newScale - Time.timeScale) > 0.0001f) | |
| { | |
| targetScale = newScale; | |
| Time.timeScale = targetScale; | |
| } | |
| EditorGUI.EndDisabledGroup(); | |
| // Presets | |
| EditorGUILayout.Space(); | |
| EditorGUILayout.BeginHorizontal(); | |
| if (GUILayout.Button("x0.25")) SetScale(0.25f); | |
| if (GUILayout.Button("x0.5")) SetScale(0.5f); | |
| if (GUILayout.Button("x1")) SetScale(1f); | |
| if (GUILayout.Button("x2")) SetScale(2f); | |
| EditorGUILayout.EndHorizontal(); | |
| // Repaint constantly while playing | |
| if (EditorApplication.isPlaying) | |
| Repaint(); | |
| } | |
| void SetScale(float value) | |
| { | |
| paused = false; | |
| targetScale = value; | |
| Time.timeScale = targetScale; | |
| } | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment