Ejemplo n.º 1
0
    /*Check whether any of the cars passes the goal.
     * If a car passes, increase the laps they've finished.
     * If they've finished their third lap, give them their ranking and
     * finish the race once the player finishes their third lap.*/
    void OnTriggerEnter(Collider other)
    {
        if (other.transform.tag == "CarPlayer")
        {
            if (racing[0] == true)
            {
                lapsFinished[0]++;
                gui.CurrentLap = lapsFinished[0];


                if (lapsFinished[0] == lapsToFinish)
                {
                    CheckRanking(0);
                    gui.PlayerPosition = ranking[0];
                    gui.RaceFinished();
                    musicPlayer.RaceFinished(ranking[0]);
                }
                else if (lapsFinished[0] == (lapsToFinish - 1))
                {
                    musicPlayer.FinalLapPlay();
                    gui.FinalLapPrompt();
                }
            }
            else
            {
                racing[0]       = true;
                lapsFinished[0] = 1;
            }
        }
        else if (other.transform.tag == "Computer1")
        {
            if (racing[1] == true)
            {
                lapsFinished[1]++;
                if (lapsFinished[1] == lapsToFinish)
                {
                    CheckRanking(1);
                }
            }
            else
            {
                racing[1]       = true;
                lapsFinished[1] = 1;
            }
        }
        else if (other.transform.tag == "Computer2")
        {
            if (racing[2] == true)
            {
                lapsFinished[2]++;
                if (lapsFinished[2] == lapsToFinish)
                {
                    CheckRanking(2);
                }
            }
            else
            {
                racing[2]       = true;
                lapsFinished[2] = 1;
            }
        }
        else if (other.transform.tag == "Computer3")
        {
            if (racing[3] == true)
            {
                lapsFinished[3]++;
                if (lapsFinished[3] == lapsToFinish)
                {
                    CheckRanking(3);
                }
            }
            else
            {
                racing[3]       = true;
                lapsFinished[3] = 1;
            }
        }
    }