예제 #1
0
    public void Update()
    {
        float fallTime = 1.8f;         // in seconds

        for (int i = 0; i < numTracks; ++i)
        {
            // issue all beats that we need to catch up
            while (beatsDropped[i] < GetFloatBeats(audioData.time + fallTime))
            {
                beatsDropped[i] += 1;                 // this line is first because if you forget it, the while loop will hang
                // check if this is an actual beat according to the song
                int isBeat = beats[i, beatsDropped[i] - 1];
                if (isBeat == 1)
                {
                    // create a new beat object
                    GameObject thisBeat = (GameObject)Instantiate(beatPrefabs[i]);
                    // get the script for the beat (this has the variables)
                    FallingButton thisBeatScript = thisBeat.GetComponent <FallingButton>();
                    // set the start point as the vanishing point
                    thisBeatScript.startPoint = startButtonFallPoint.transform.localPosition;
                    // set the button to know us so it can make us lose
                    thisBeatScript.music = this;
                    // set the endpoint to be where the player taps
                    thisBeatScript.endPoint = endButtonFallPoints[i].transform.localPosition;
                    // put the beat in the correct track
                    thisBeat.transform.SetParent(tracks[i].transform, worldPositionStays: true);
                    // put the newest beat behind the rest
                    thisBeat.transform.SetAsFirstSibling();
                    // if we're late on this beat, start it with some time to catch up (this doesn't seem to work)
                    thisBeatScript.totalTime = (GetFloatBeats(audioData.time + fallTime) - beatsDropped[i]);
                    // setting the fallTime will initialize the object
                    thisBeatScript.fallTime = fallTime;
                }
            }
        }
        if (!audioData.isPlaying)
        {
            SceneManager.LoadScene("Win Scene");
        }
    }
예제 #2
0
 public void HitBeatButton(int track)
 {
     // this is called by the beat button
     if (tracks[track].transform.childCount > 0)
     {
         Transform     lastChild        = tracks[track].transform.GetChild(tracks[track].transform.childCount - 1);
         FallingButton fallButt         = lastChild.gameObject.GetComponent <FallingButton>();
         float         difficultyMargin = .3f;
         if (Mathf.Abs(fallButt.fallTime - fallButt.totalTime) < difficultyMargin)
         {
             PlayerStats.Hits      += 1;
             PlayerStats.Meter_Val += 1;
             if (PlayerStats.Meter_Val > PlayerStats.Meter_Max)
             {
                 PlayerStats.Meter_Val = PlayerStats.Meter_Max;
             }
             lightUpGraphics[track].GetComponent <LightUp>().DoLightUp();
             Destroy(lastChild.gameObject);
         }
         else
         {
             PlayerStats.Misses    += 1;
             PlayerStats.Meter_Val -= 1;
             if (PlayerStats.Meter_Val <= 0)
             {
                 this.Lose();
             }
         }
     }
     else
     {
         PlayerStats.Misses    += 1;
         PlayerStats.Meter_Val -= 1;
         if (PlayerStats.Meter_Val <= 0)
         {
             this.Lose();
         }
     }
 }