using UnityEngine; public class SimulationManager : MonoBehaviour { Animator[] allAnimator; public bool isSpeedUp; public float upSpeedValue = 5; Panel_Property property; Panel_Result resultUI; private void Awake() { property = FindAnyObjectByType(); allAnimator = FindObjectsByType(FindObjectsSortMode.None); resultUI = FindAnyObjectByType(); resultUI.gameObject.SetActive(false); AnimationPlay(false); } void Update() { if (Input.GetKeyDown(KeyCode.Keypad1)) { property.Activate(0); } if (Input.GetKeyDown(KeyCode.Keypad2)) { property.Activate(1); } if (Input.GetKeyDown(KeyCode.Keypad3)) { property.Activate(2); } if (Input.GetKeyDown(KeyCode.Keypad4)) { property.Activate(3); } if (Input.GetKeyDown(KeyCode.Keypad5)) { property.Activate(4); } if (Input.GetKeyDown(KeyCode.Keypad6)) { property.Activate(5); } if (Input.GetKeyDown(KeyCode.Keypad7)) { property.Activate(6); } if (Input.GetKeyDown(KeyCode.S)) { ToggleAnimationSpeedUp(); } if (Input.GetKeyDown(KeyCode.Space)) { AnimationPlay(false); ShowResultUI(); } } public void AnimationPlay(bool playing) { foreach (Animator animator in allAnimator) { if (playing) { animator.Play(animator.GetCurrentAnimatorStateInfo(0).fullPathHash); animator.speed = Random.Range(0.5f, 1.5f); } else { animator.speed = 0; } } } void ToggleAnimationSpeedUp() { isSpeedUp = !isSpeedUp; if (isSpeedUp) { foreach (Animator animator in allAnimator) { animator.speed *= upSpeedValue; } } else { foreach (Animator animator in allAnimator) { animator.speed /= upSpeedValue; } } } void ShowResultUI() { resultUI.gameObject.SetActive(true); } }