Advertisement
Ringo276

Untitled

Apr 21st, 2020
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SongManager : MonoBehaviour
  6. {
  7. float songPosition, songPosInBeats, secPerBeat, dsptimesong;
  8. public float bpm;
  9. public int nextIndex = 0;
  10. public float spawnX;
  11. public float hitRange;
  12. public RBM rbm;
  13. public GameObject instance;
  14. public GameObject upArrowNote, downArrowNote, leftArrowNote, rightArrowNote;
  15.  
  16. //array is used to tell the game what beat to spawn each note on
  17. float[] notes = new float[137] { 1f, 1.666f, 2f, 2.666f, 3f, 3.666f, 4, 4.666f, //measure one
  18. 5f, 5.666f, 6f, 6.666f, 7f, 7.666f, 8f, //measure two
  19. 9f, 9.666f, 10f, 10.666f, 11f, 11.666f, 12f, 12.666f, //measure three
  20. 13f, 13.666f, 14f, 14.666f, 15f, 15.666f, 16, //measure four
  21. 17f, 18f, 18.666f, 19f, 20f, //measure five
  22. 21f, 22f, 23f, 23.666f, 24f, //measure six
  23. 25f, 26f, 26.666f, 27f, 28f, //measure seven
  24. 29f, 30f, 31f, 31.666f, 32f, //measure eight
  25. 33f, 33.666f, 34f, 34.666f, 35f, 35.666f, 36f, 36.666f, //measure nine
  26. 37f, 37.666f, 38f, 38.666f, 39f, 39.666f, 40f, //measure ten
  27. 41f, 41.666f, 42f, 42.666f, 43f, 43.666f, 44f, 44.666f, //measure eleven
  28. 45f, 45.666f, 46f, 46.666f, 47f, 47.666f, 48f, //measure twelve
  29. 49f, 49.666f, 50f, 50.666f, 51f, 51.666f, 52f, 52.666f, //measure thirteen
  30. 53f, 53.666f, 54f, 54.666f, 55f, 55.666f, 56, //measure fourteen
  31. 57f, 57.666f, 58f, 58.666f, 59f, 59.666f, 60f, 60.666f, //measure fifteen
  32. 61f, 61.666f, 62f, 62.666f, 63f, 63.666f, 64f, //measure sixteen
  33. 65f,66f, 66.666f, 67f, 68f, //measure seventeen
  34. 69, 70f, 71f, 71.666f, 72f, //measure eighteen
  35. 73f, 74f, 74.666f, 75f, 76f, //measure nineteen
  36. 77f, 78f, 79f, 79.666f, 80f, //measure twenty
  37. 81f, 81.666f, 82f, 82.666f, 83f, 83.666f, 84f //measure twentyone
  38. };
  39.  
  40. //array is used to tell whether each note is up, down, left, or right
  41. //up = 1 down = 2 left = 3 right = 4
  42. public int [] whichNote = new int[137] {4, 3, 3, 4, 2, 3, 1, 2, //measure one
  43. 4, 2, 3, 2, 3, 2, 2, //measure two
  44. 4, 3, 3, 4, 2, 3, 1, 2, // measure three
  45. 4, 2, 3, 2, 3, 3, 2, //measure four
  46. 2, 2, 1, 1, 2, //measure five
  47. 1, 2, 3, 3, 3, //measure six
  48. 2, 2, 1, 1, 2, //measure seven
  49. 1, 2, 3, 3, 3, //measure eight
  50. 1, 4, 3, 1, 1, 2, 3, 1, //measure nine
  51. 3, 4, 3, 4, 2, 3, 1, //measure ten
  52. 1, 2, 3, 4, 2, 3, 2, 2, //measure eleven
  53. 4, 2, 3, 2, 2, 3, 1, //measure twelve
  54. 4, 3, 3, 4, 2, 3, 1, 2, // measure thirteen
  55. 4, 2, 3, 2, 3, 2, 2, // measure fourteen
  56. 4, 3, 3, 4, 2, 3, 1, 2, //measure fifteen
  57. 4, 2, 3, 2, 3, 2, 2, //measure sixteen
  58. 2, 2, 1, 1, 2, //measure seventeen
  59. 1, 2, 3, 3, 3, //measure eighteen
  60. 2, 2, 1, 1, 2, //measure nineteen
  61. 1, 2, 3, 3, 3, //measure twenty
  62. 4, 2, 3, 2, 3, 2, 2, //measure twentyone
  63. };
  64.  
  65. void Start()
  66. {
  67. //calculate time in seconds between beats
  68. secPerBeat = 60f / bpm;
  69.  
  70. //recording time when the song starts
  71. dsptimesong = (float) AudioSettings.dspTime;
  72.  
  73. //start the song
  74.  
  75. }
  76.  
  77. // Update is called once per frame
  78. void Update()
  79. {
  80. //calculate the position in seconds
  81. songPosition = (float)(AudioSettings.dspTime - dsptimesong);
  82.  
  83. //calculate the position in beats
  84. songPosInBeats = songPosition / secPerBeat;
  85.  
  86. //spawning notes
  87. if (songPosInBeats >= notes[nextIndex] && whichNote[nextIndex] == 1)
  88. {
  89. instance = Instantiate(upArrowNote, new Vector3(spawnX, whichNote[nextIndex], 0), Quaternion.identity);
  90. instance.GetComponent<NoteMove>().mannyBoi = rbm;
  91.  
  92. nextIndex++;
  93. }
  94. else if (songPosInBeats >= notes[nextIndex] && whichNote[nextIndex] == 2)
  95. {
  96. instance = Instantiate(downArrowNote, new Vector3(spawnX, whichNote[nextIndex], 0), Quaternion.identity);
  97. instance.GetComponent<NoteMove>().mannyBoi = rbm;
  98.  
  99. nextIndex++;
  100. }
  101. else if (songPosInBeats >= notes[nextIndex] && whichNote[nextIndex] == 3)
  102. {
  103. instance = Instantiate(leftArrowNote, new Vector3(spawnX, whichNote[nextIndex], 0), Quaternion.identity);
  104. instance.GetComponent<NoteMove>().mannyBoi = rbm;
  105.  
  106. nextIndex++;
  107. }
  108. else if (songPosInBeats >= notes[nextIndex] && whichNote[nextIndex] == 4)
  109. {
  110. instance = Instantiate(rightArrowNote, new Vector3(spawnX, whichNote[nextIndex], 0), Quaternion.identity);
  111. instance.GetComponent<NoteMove>().mannyBoi = rbm;
  112.  
  113. nextIndex++;
  114. }
  115.  
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement