Exemplo n.º 1
0
    private void OnTriggerStay(Collider other)
    {
        bool newCheckpointAdded = false;

        int checkpointNumber = -1;

        int.TryParse(other.gameObject.name, out checkpointNumber);

        if (checkpointNumber != -1)            //hit a checkpoint
        {
            if (reachedCheckpoints.Count == 0) //first checkpoint
            {
                reachedCheckpoints.Push(checkpointNumber);
                newCheckpointAdded = true;
            }
            else
            {
                if (reachedCheckpoints.Peek() + 1 == checkpointNumber) //the next checkpoint was hit
                {
                    reachedCheckpoints.Push(checkpointNumber);
                    newCheckpointAdded = true;
                }
            }

            if (newCheckpointAdded)
            {
                audioData.pitch = ((float)checkpointNumber / 40) + 1;
                audioData.Play(0);
                Debug.Log(checkpointNumber);

                if (reachedCheckpoints.Peek() == 36) //finish
                {
                    BallScript ballScr = GetComponent <BallScript>();
                    ballScr.EnableFinishScreen();
                }
            }
        }
    }