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