private void ManageReferences() { // get reference to the popUp GameObject _connectionPopUp = GameObject.Find("ConnectPopup"); // set reference to play button _playBtn = GameObject.Find("Play Btn").GetComponent <Button>(); // set reference to exit button _exitBtn = GameObject.Find("Exit Btn").GetComponent <Button>(); // reference to the Connect button _connectBtn = GameObject.Find("ConnectBtn").GetComponent <Button>(); // reference to the cancel button _cancelBtn = GameObject.Find("CancelBtn").GetComponent <Button>(); // reference to InputField _playerInputField = GameObject.Find("inputFieldPlayerName").GetComponent <Text>(); // reference to server ip inputField _serverIpInput = GameObject.Find("inputFieldServer").GetComponent <Text>(); // disable PopUp _connectionPopUp.SetActive(false); // set buttons active _playBtn.enabled = true; _exitBtn.enabled = true; // reference to the networkController _netWorkController = GameObject.Find("NetworkController").GetComponent <ClientNetworkController>(); // reference to the connection screen _connectionScreen = GetComponent <ConnectionScreen>(); }
// func is called when a new player is spawned public void OnPlayerSpanw(Guid pId, string pName, int pNum, CutleryColor pColor, bool isLocal, ClientNetworkController clientNetwork) { // save on func vars the id, name and color of the spawned player _playerId = pId; _playerName = pName; _playerColor = new Color(pColor.R, pColor.G, pColor.B); _playerNumber = pNum; //the network manager defines if this player is the local player _isLocal = isLocal; // set the components to the info passed _playernameText.text = _playerName; _playerColorImage.color = _playerColor; // load reference for the player score if (_playerNumber == 1) { // if player is the number 1 player // find and save the reference to the score displayer _ScoreDisplayer = GameObject.Find("Player1 scoreText").GetComponent <Text>(); // find and save the reference to the score name displayer _scoreNameDisplayer = GameObject.Find("Player1ScoreName").GetComponent <Text>(); } // if is the player 2 else if (_playerNumber == 2) { Debug.Log("Player 2 setting goal box"); //if player is the number 2 player // find and save the reference to the score displayer _ScoreDisplayer = GameObject.Find("Player2 scoreText").GetComponent <Text>(); // find and save the reference to the score name displayer _scoreNameDisplayer = GameObject.Find("Player2ScoreName").GetComponent <Text>(); } // set the player name and score _ScoreDisplayer.text = "0"; _scoreNameDisplayer.text = _playerName; // if is not a local , all the positions are controlled from the server if (!_isLocal) { // remove the rigidbody and the boxColider Destroy(_playerRigidbody); Destroy(GetComponent <BoxCollider2D>()); // change the transparency of the nonLocal player _playerRenderer.color = new Color(_playerRenderer.color.r, _playerRenderer.color.g, _playerRenderer.color.b, 0.5f) * _playerColor; } else { //save the controller _clientNet = clientNetwork; // saving the old states _oldPosition = _playerTransform.position; // setting the jump state _lateJumpState = 0; // get the reference to the endGameScreenController _endScreenController = GameObject.Find("EndGameScreen").GetComponent <EndGameScreenController>(); } }