Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using UnityEngine;
- public class Loop : MonoBehaviour
- {
- public enum state {Syncing, PlayingGood, PlayingOkay, PlayingBad, Inactive};
- state loopState = state.Inactive;
- state lastState;
- public AudioClip MySound;
- public PlayerManager pM;
- public GroupManager gM;
- public ParticleManager parM;
- public SpriteRenderer sR;
- public MusickSystem mS;
- public Color[] stateColours = new Color[Enum.GetValues(typeof(state)).Length -1];
- public int[] beatsperStates = new int[Enum.GetValues(typeof(state)).Length - 1];
- public int BeatTempo = 4;
- public int amountOfBeats = 0;
- private void Start()
- {
- SetColor(0);
- }
- public state TurnOff()
- {
- lastState = loopState;
- loopState = state.Inactive;
- return lastState;
- }
- public void TurnOn()
- {
- loopState = state.Syncing;
- SetColor(0);
- amountOfBeats = 0;
- }
- public void PauseLoop(bool _pause)
- {
- if (_pause)
- {
- lastState = loopState;
- loopState = state.Inactive;
- }
- else
- {
- loopState = lastState;
- }
- }
- public void beat(int time)
- {
- if (time % BeatTempo == 0 && loopState != state.Inactive)
- {
- if (loopState == state.Syncing)
- {
- amountOfBeats++;
- if (amountOfBeats == beatsperStates[0])
- {
- amountOfBeats = 0;
- loopState = state.PlayingGood;
- SetColor((int)loopState);
- gM.GivePlayerScore();
- }
- }
- else
- {
- UpdatePlayingOnBeat();
- }
- }
- }
- void UpdatePlayingOnBeat ()
- {
- mS.PlaySound(MySound);
- if (loopState == state.PlayingGood || loopState == state.PlayingOkay)
- {
- amountOfBeats++;
- if (amountOfBeats == beatsperStates[(int)loopState])
- {
- amountOfBeats = 0;
- loopState++;
- SetColor((int)loopState);
- }
- }
- else
- {
- pM.DamagePlayer();
- }
- }
- public void ActivateParticles(GroupManager.SkoreLevel TypeOfScore)
- {
- parM.PlayParticle((int)TypeOfScore);
- }
- public void SetColor(int color)
- {
- sR.color = stateColours[color];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement