You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
999 B

4 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BlockInput : MonoBehaviour
  5. {
  6. public Character character;
  7. public BlockReader blockReader;
  8. public float waitTime;
  9. public void Update()
  10. {
  11. if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Space))
  12. ReadNext();
  13. else if (Input.GetKeyDown(KeyCode.Space))
  14. ReadAll();
  15. }
  16. [ContextMenu("Read Next")]
  17. public void ReadNext()
  18. {
  19. StartCoroutine(blockReader.Read(character, waitTime));
  20. }
  21. public void ReadAll()
  22. {
  23. StartCoroutine(ReadRoutine(waitTime));
  24. }
  25. public void FinishedReading()
  26. {
  27. blockReader.Reset();
  28. blockReader.Clear();
  29. }
  30. public IEnumerator ReadRoutine(float waitTime)
  31. {
  32. while (!blockReader.Finished)
  33. {
  34. ReadNext();
  35. yield return new WaitForSeconds(waitTime);
  36. }
  37. FinishedReading();
  38. }
  39. }