Exemplo n.º 1
0
            public void SkipToBeat(float beat, float distancePerBeat)
            {
                this.currentBeat = beat;
                this.lastBeat    = beat;
                // Destroy bars on screen //
                for (int count = 0; count < bars.Count; count++)
                {
                    bars[count].gameObject.SetActive(false);
                    GameObject.Destroy(bars[count].gameObject);
                }
                bars = new List <BeatBar>();
                // Create new bars to match current beat //
                float currentZ = spawnAtZ;
                int   barCount = 0;

                while (currentZ > destroyAtZ)
                {
                    BeatBar bar         = GameObject.Instantiate(BeatMap.BarPrefab, null).GetComponent <BeatBar>();
                    Vector3 barPosition = new Vector3(0, 0, spawnAtZ);
                    barPosition.z = currentZ;
                    bar.SetBeatNumber((int)beat - barCount);
                    bar.transform.position = barPosition;
                    bars.Add(bar);
                    currentZ -= distancePerBeat;
                    barCount++;
                }
            }
Exemplo n.º 2
0
            public void Update()
            {
                if (DEBUG)
                {
                    Debug.LogWarning("Current beat - " + currentBeat);
                }
                // Increment or Decrement the current beat //
                if (!rewinding)
                {
                    currentBeat += beatsPerSecond * Time.deltaTime;
                }
                else
                {
                    currentBeat -= beatsPerSecond * Time.deltaTime;
                }

                // Next beat has started //
                if ((int)(currentBeat + BeatMap.beatsToReachPlayer) > lastBeatBarPlaced)
                {
                    lastBeatBarPlaced = (int)(currentBeat + BeatMap.beatsToReachPlayer);
                    // Create new bar //
                    BeatBar newBar = GameObject.Instantiate(BeatMap.BarPrefab).GetComponent <BeatBar>();
                    if (!rewinding)
                    {
                        Vector3 spawnPosition = new Vector3(0, 0, spawnAtZ);
                        newBar.transform.position = spawnPosition;
                        newBar.SetBeatNumber((int)(currentBeat + BeatMap.beatsToReachPlayer));
                        if (DEBUG)
                        {
                            Debug.Log("Creating bar for beat # - " + newBar.GetBeatNumber());
                        }
                        newBar.transform.SetParent(BarContainer.transform);
                        bars.Add(newBar);

                        // Destory old bars //
                        List <BeatBar> barsToDestroy = new List <BeatBar>();
                        foreach (BeatBar bar in bars)
                        {
                            if (bar.transform.position.z < destroyAtZ)
                            {
                                barsToDestroy.Add(bar);
                            }
                        }
                        for (int count = 0; count < barsToDestroy.Count; count++)
                        {
                            barsToDestroy[count].gameObject.SetActive(false);
                            bars.Remove(barsToDestroy[count]);
                            GameObject.Destroy(barsToDestroy[count].gameObject);
                        }
                    }
                    else
                    {
                        Vector3 spawnPosition = new Vector3(0, 0, destroyAtZ);
                        newBar.transform.position = spawnPosition;
                        newBar.SetBeatNumber((int)currentBeat);
                        bars.Add(newBar);

                        // Destroy bars //
                        List <BeatBar> barsToDestroy = new List <BeatBar>();
                        foreach (BeatBar bar in bars)
                        {
                            if (bar.transform.position.z > spawnAtZ)
                            {
                                barsToDestroy.Add(bar);
                            }
                        }
                        for (int count = 0; count < barsToDestroy.Count; count++)
                        {
                            barsToDestroy[count].gameObject.SetActive(false);
                            bars.Remove(barsToDestroy[count]);
                            GameObject.Destroy(barsToDestroy[count].gameObject);
                        }
                    }
                }
            }