Esempio n. 1
0
        void OnTriggerEnter(Collider other)
        {
            Debug.Log("PlayerMove: Hit a collider");
            if (!photonView.IsMine)
            {
                Debug.Log("PlayerMove: It wasn't me");
                return;
            }

            if (other.tag == "Checkpoint")
            {
                Debug.Log("PlayerMove: Checkpoint crossed", other);
                int checkPointNumber = other.GetComponent <Checkpoint>().checkPointNumber;
                checkPoints[checkPointNumber] = true;
                return;
            }
            if (other.tag == "Finish")
            {
                Debug.Log("PlayerMove: Crossed the finish line");
                hasStarted = true;
                bool lapDone  = true;
                bool lapStart = true;
                // Check if we need to start the timer...
                for (int i = 0; i < numCheckpoints; i++)
                {
                    if (checkPoints[i])
                    {
                        lapStart = false;
                        Debug.Log("PlayerMove: Don't restart timer");
                    }
                }
                for (int i = 0; i < numCheckpoints; i++)
                {
                    if (!checkPoints[i])
                    {
                        lapDone = false;
                        Debug.Log("PlayerMove: You missed a checkpoint");
                    }
                }
                if (lapDone)
                {
                    Debug.Log("PlayerMove: Yay, you crossed the finsh line!");
                    laps++;
                    lastTime = Time.time - startTime;
                    if (bestTime == 0 || bestTime > lastTime)
                    {
                        bestTime = lastTime;
                    }
                    for (int i = 0; i < numCheckpoints; i++)
                    {
                        checkPoints[i] = false;
                    }
                    lapStart = true;
                    StartCoroutine(webCalls.UploadLap(PlayerPrefs.GetString("PlayerEmail"), PhotonNetwork.NickName, lastTime, PhotonNetwork.CurrentRoom.PlayerCount, PhotonNetwork.CurrentRoom.Name, (int)PhotonNetwork.CurrentRoom.CustomProperties["map"]));
                    ExitGames.Client.Photon.Hashtable hashtable = new ExitGames.Client.Photon.Hashtable();
                    hashtable.Add("laps", laps);
                    hashtable.Add("best", bestTime);
                    hashtable.Add("last", lastTime);
                    PhotonNetwork.LocalPlayer.SetCustomProperties(hashtable);
                }
                if (lapStart)
                {
                    Debug.Log("PlayerMove: Starting a lap...");
                    startTime = Time.time;
                }
            }
            Debug.Log("PlayerMove: Laps - " + laps + " Best - " + bestTime + " Last - " + lastTime);
        }