SledgeBoost.cs 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using System.Collections;
  3. public class SledgeBoost : MonoBehaviour
  4. {
  5. private static SledgeBoost _instance;
  6. // Use this for initialization
  7. void Start ()
  8. {
  9. _instance = this;
  10. gameObject.SetActive(false);
  11. }
  12. // Update is called once per frame
  13. void Update () {
  14. }
  15. public static void Boost()
  16. {
  17. if (!_instance)
  18. {
  19. return;
  20. }
  21. _instance.gameObject.SetActive(true);
  22. _instance.StartCoroutine(_instance.BoostRoutine());
  23. }
  24. private IEnumerator BoostRoutine()
  25. {
  26. for (int i = 0; i < 20; i++)
  27. {
  28. Time.timeScale += 0.05f;
  29. yield return new WaitForSeconds(0.1f);
  30. }
  31. yield return new WaitForSeconds(6f);
  32. for (int i = 0; i < 20; i++)
  33. {
  34. Time.timeScale -= 0.05f;
  35. yield return new WaitForSeconds(0.1f);
  36. }
  37. Time.timeScale = 1f;
  38. gameObject.SetActive(false);
  39. }
  40. }