コード例 #1
0
    void OnTriggerEnter(Collider other)
    {
        CarPathFollow carPathFollow = other.GetComponent <CarPathFollow> ();

        if (other.tag == "Car" && carPathFollow.iLapCounter < lapNumber + 1)                                                                                                            // A car finish a lap
        {
            if (b_ActivateLapCounter)
            {
                if (b_Multiplayer)
                {
#if PHOTON_UNITY_NETWORKING
                    for (var j = 0; j < gManagerPhoton.tmpCarList.Count; j++)
                    {
                        if (gManagerPhoton.tmpCarList[j] && gManagerPhoton.tmpCarList[j].gameObject == other.gameObject)
                        {
                            if (gManagerPhoton.tmpPhotonManagerList[j].GetComponent <PhotonView>().IsMine)
                            {
                                if (carPathFollow.iLapCounter <= lapNumber + 1)
                                {
                                    Debug.Log("Lap");
                                    Txt_P1_Lap.text = "Lap " + (gManagerPhoton.tmpCarList[j].GetComponent <CarPathFollow>().iLapCounter).ToString() + "/" + lapNumber.ToString();
                                }
                            }
                        }
                    }
#endif
                }
                else
                {
                    if (carPathFollow.iLapCounter <= lapNumber + 1)
                    {
                        if (car[0] != null && car[0].gameObject == other.gameObject && Txt_P1_Lap)
                        {
                            Txt_P1_Lap.text = "Lap " + (car[0].iLapCounter).ToString() + "/" + lapNumber.ToString();
                        }
                        if (car[1] != null && car[1].name == other.name && Txt_P2_Lap)
                        {
                            Txt_P2_Lap.text = "Lap " + (car[1].iLapCounter).ToString() + "/" + lapNumber.ToString();
                        }
                    }
                }
            }
        }

        if (b_ActivateLapCounter)
        {
            if (other.tag == "Car" && carPathFollow.iLapCounter >= lapNumber + 1)                                                                                                       // A car finish the race
            //Debug.Log (other.name + " finished the race");
            {
                for (var i = 0; i < car.Count; i++)
                {
                    if (car[i] != null && car[i].gameObject == other.gameObject && raceFinished[i])
                    {
                        carController [i].raceIsFinished = true;
                    }


                    if (car [i] != null && car [i].gameObject == other.gameObject && !raceFinished [i])
                    {
                        raceFinished [i] = true;
                        carTime [i]      = Timer;
                        carController [i].raceIsFinished = true;

                        //GM_Photon.DisplayScoreMultiOnline(carController[i].gameObject);

                        if (PlayerPrefs.GetString("Which_GameMode") == "OnlineMultiPlayer")
                        {
                            #if PHOTON_UNITY_NETWORKING
                            PlayerPrefs.SetInt("CurrentScore", Mathf.RoundToInt(carTime[i] * 1000));
                            MCR.GameManager_MCR_Photon GM_Photon = GameObject.Find("GM_Photon").GetComponent <MCR.GameManager_MCR_Photon>();
                            if (GM_Photon != null)
                            {
                                Debug.Log(" GM_Photon ");
                            }
                            else
                            {
                                Debug.Log(" GM_Photon nuii");
                            }
                            Debug.Log(" carTime[ " + i + "  ] " + carTime[i]);
                            StartCoroutine(
                                GM_Photon.WinProcessOnlineMultiplayer(
                                    carController[i].gameObject,
                                    Mathf.RoundToInt(carTime[i] * 1000)));
                            #endif
                        }
                        else if (i == 0 && player2IsManageByCPU)
                        {
                            PlayerPrefs.SetInt("CurrentScore", Mathf.RoundToInt(carTime [i] * 1000));
                            gameManager.RaceIsFinished();
                            CheckIfNextTrackMustBeUnlocked();
                        }
                        else if ((i == 0 || i == 1) && !player2IsManageByCPU && carController [0] != null && carController [0].raceIsFinished && carController [1] != null && carController [1].raceIsFinished)
                        {
                            gameManager.RaceIsFinished();
                            CheckIfNextTrackMustBeUnlocked();
                        }
                    }
                }
            }
        }
    }