Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        PhotonNetwork.AutomaticallySyncScene = true;

        if (PhotonNetwork.IsConnectedAndReady && PhotonNetwork.IsMasterClient)
        {
            _fruitController.StartSpawning();
        }

        if (PhotonNetwork.IsConnectedAndReady)
        {
            _playerRankingScreen.SetActive(false);

            _gameTimeLimit = NetworkCustomSettings.GAME_TIME;
            _gameTimeLeft  = _gameTimeLimit;
            _gameEnding    = false;

            int    playerPosition = 0;
            object playerNum;
            if (PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue(NetworkCustomSettings.PLAYER_NUMBER, out playerNum))
            {
                playerPosition = (int)playerNum - 1;
            }
            Vector3 startingPosition = _startingPositions[playerPosition].position;

            object playerSelection;
            if (PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue(NetworkCustomSettings.PLAYER_SELECTION_NUMBER, out playerSelection))
            {
                PhotonNetwork.Instantiate(_playerPrefabs[(int)playerSelection].name, startingPosition, Quaternion.identity);
            }
#if UNITY_ANDROID
            Debug.Log("Android no cursor");
#else
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible   = false;
#endif
        }
        else
        {
            ScoreKeeper scoreKeeper = GameObject.FindObjectOfType <ScoreKeeper>();
            if (scoreKeeper != null)
            {
                Destroy(scoreKeeper.gameObject);
            }
            _gameController.LoadNextLevel(0);
        }
    }