SlowMo.cs 680 B

12345678910111213141516171819202122232425262728293031
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace RootMotion.Demos {
  4. /// <summary>
  5. /// Going slow motion on user input
  6. /// </summary>
  7. public class SlowMo : MonoBehaviour {
  8. public KeyCode[] keyCodes;
  9. public bool mouse0;
  10. public bool mouse1;
  11. public float slowMoTimeScale = 0.3f;
  12. void Update () {
  13. Time.timeScale = IsSlowMotion()? slowMoTimeScale: 1f;
  14. }
  15. private bool IsSlowMotion() {
  16. if (mouse0 && Input.GetMouseButton(0)) return true;
  17. if (mouse1 && Input.GetMouseButton(1)) return true;
  18. for (int i = 0; i < keyCodes.Length; i++) {
  19. if (Input.GetKey(keyCodes[i])) return true;
  20. }
  21. return false;
  22. }
  23. }
  24. }