Advertisement
Guest User

Loop

a guest
Nov 9th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5.  
  6. public class Loop : MonoBehaviour
  7. {
  8. public enum state {Syncing, PlayingGood, PlayingOkay, PlayingBad, Inactive};
  9. state loopState = state.Inactive;
  10. state lastState;
  11. public AudioClip MySound;
  12. public PlayerManager pM;
  13. public GroupManager gM;
  14. public ParticleManager parM;
  15. public SpriteRenderer sR;
  16. public MusickSystem mS;
  17.  
  18. public Color[] stateColours = new Color[Enum.GetValues(typeof(state)).Length -1];
  19. public int[] beatsperStates = new int[Enum.GetValues(typeof(state)).Length - 1];
  20.  
  21. public int BeatTempo = 4;
  22. public int amountOfBeats = 0;
  23.  
  24. private void Start()
  25. {
  26. SetColor(0);
  27. }
  28. public state TurnOff()
  29. {
  30. lastState = loopState;
  31. loopState = state.Inactive;
  32. return lastState;
  33. }
  34. public void TurnOn()
  35. {
  36. loopState = state.Syncing;
  37. SetColor(0);
  38. amountOfBeats = 0;
  39. }
  40. public void PauseLoop(bool _pause)
  41. {
  42. if (_pause)
  43. {
  44. lastState = loopState;
  45. loopState = state.Inactive;
  46. }
  47. else
  48. {
  49. loopState = lastState;
  50. }
  51. }
  52. public void beat(int time)
  53. {
  54. if (time % BeatTempo == 0 && loopState != state.Inactive)
  55. {
  56. if (loopState == state.Syncing)
  57. {
  58. amountOfBeats++;
  59. if (amountOfBeats == beatsperStates[0])
  60. {
  61. amountOfBeats = 0;
  62. loopState = state.PlayingGood;
  63. SetColor((int)loopState);
  64. gM.GivePlayerScore();
  65. }
  66. }
  67. else
  68. {
  69. UpdatePlayingOnBeat();
  70. }
  71. }
  72. }
  73. void UpdatePlayingOnBeat ()
  74. {
  75. mS.PlaySound(MySound);
  76. if (loopState == state.PlayingGood || loopState == state.PlayingOkay)
  77. {
  78. amountOfBeats++;
  79. if (amountOfBeats == beatsperStates[(int)loopState])
  80. {
  81. amountOfBeats = 0;
  82. loopState++;
  83. SetColor((int)loopState);
  84. }
  85. }
  86. else
  87. {
  88. pM.DamagePlayer();
  89. }
  90. }
  91. public void ActivateParticles(GroupManager.SkoreLevel TypeOfScore)
  92. {
  93. parM.PlayParticle((int)TypeOfScore);
  94. }
  95. public void SetColor(int color)
  96. {
  97. sR.color = stateColours[color];
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement