void OnPlayerTurn(SocketIOEvent socketIOEvent) { string data = socketIOEvent.data.ToString(); PlayerJSON otherplayerJSON = PlayerJSON.CreateFromJSON(data); Quaternion rotation = Quaternion.Euler(otherplayerJSON.rotation[0], otherplayerJSON.rotation[1], otherplayerJSON.rotation[2]); // if it is the current player exit if (otherplayerJSON.pseudo == playerNameInputLogin.text || otherplayerJSON.pseudo == playerNameInputNewAccount.text) { return; } GameObject p = GameObject.Find(otherplayerJSON.pseudo) as GameObject; if (p != null) { p.transform.rotation = rotation; Transform cp = p.transform.Find("FirstPersonCharacter"); if (cp != null) { cp.transform.rotation = rotation; } else { Debug.Log(" cp fail"); } } }
void OnPlay(SocketIOEvent socketIOEvent) { print("you joined"); startMenuCamera.gameObject.SetActive(false); string data = socketIOEvent.data.ToString(); print("your JSON data was recieved"); PlayerJSON currentUserJSON = PlayerJSON.CreateFromJSON(data); print("your JSON was created : " + data); Vector3 position = new Vector3(currentUserJSON.playerPosition[0], currentUserJSON.playerPosition[1], currentUserJSON.playerPosition[2]); print("your name isssssssssssssssss "); Quaternion rotation = Quaternion.Euler(currentUserJSON.playerRotation[0], currentUserJSON.playerRotation[1], currentUserJSON.playerRotation[2]); print("your name isssssssssssssssss "); GameObject p = Instantiate(player, position, rotation) as GameObject; MultiPlayerController pc = p.GetComponent <MultiPlayerController>(); Transform t = p.transform.Find("Healthbar Canvas"); Transform t1 = t.transform.Find("Player Name"); Text playerName = t1.GetComponent <Text>(); playerName.text = currentUserJSON.name; pc.isLocalPlayer = true; p.name = currentUserJSON.name; GameObject Eye = p.transform.Find("OVRCameraRig").gameObject; Eye.gameObject.SetActive(true); print("your name is " + currentUserJSON.name); }
public void OnPlayerMove(SocketIOEvent socketIOEvent) { string data = socketIOEvent.data.ToString(); PlayerJSON otherplayerJSON = PlayerJSON.CreateFromJSON(data); Debug.Log("other player " + otherplayerJSON.pseudo + " want to move"); Vector3 position = new Vector3(otherplayerJSON.position[0], otherplayerJSON.position[1], otherplayerJSON.position[2]); // if it is the current player exit if (otherplayerJSON.pseudo == playerNameInputLogin.text || otherplayerJSON.pseudo == playerNameInputNewAccount.text) { Debug.Log("pas normal"); return; } GameObject op = GameObject.Find(otherplayerJSON.pseudo) as GameObject; if (op != null) { Debug.Log(op); Debug.Log("this other player moved"); op.transform.position = position; } else { Debug.Log("this otherplayer want to move but doesnt exist"); Debug.Log(op); } }
private void OnPlayerDisconnected(SocketIOEvent socketIOEvent) { Debug.Log("player disconnected"); string data = socketIOEvent.data.ToString(); PlayerJSON playerJSON = PlayerJSON.CreateFromJSON(data); Destroy(GameObject.Find(playerJSON.name)); }
private void OnPlayerTurn(SocketIOEvent socketIOEvent) { string data = socketIOEvent.data.ToString(); PlayerJSON playerJSON = PlayerJSON.CreateFromJSON(data); Debug.Log(playerJSON.name + " is rotating " + playerJSON.rotation.ToQuaternion()); GameObject player = GameObject.Find(playerJSON.name); if (player != null) { player.transform.rotation = playerJSON.rotation.ToQuaternion(); } }
private void OnPlayerMove(SocketIOEvent socketIOEvent) { string data = socketIOEvent.data.ToString(); PlayerJSON playerJSON = PlayerJSON.CreateFromJSON(data); Debug.Log(playerJSON.name + " is moving " + data); GameObject player = GameObject.Find(playerJSON.name); if (player != null) { player.transform.position = playerJSON.position.ToVector3(); } }
private void HandleStartGame(SocketIOEvent obj) { Debug.Log("Received game start"); var playerData = PlayerJSON.CreateFromJSON(obj.data.ToString()); if (autoJoinDebug) { GameController.instance.Initialize(playerData); } else { StartGameEvent(playerData); } }
private void OnPlayerConnect(SocketIOEvent socketIOEvent) { Debug.Log("Some one joined"); string data = socketIOEvent.data.ToString(); PlayerJSON playerJSON = PlayerJSON.CreateFromJSON(data); // check if he already join if (GameObject.Find(playerJSON.name) != null) { return; } GameObject player = SpawnManager.Instance.SpawnPlayer(playerJSON.name, playerJSON.position.ToVector3(), playerJSON.rotation.Euler()); PlayerController pc = player.GetComponent <PlayerController> (); pc.isLocalPlayer = false; }
public void OnOtherPlayerConnected(SocketIOEvent socketIOEvent) { string data = socketIOEvent.data.ToString(); Debug.Log(data); PlayerJSON otherplayerJSON = PlayerJSON.CreateFromJSON(data); Debug.Log("other player " + otherplayerJSON.pseudo + " is connected"); Vector3 position = new Vector3(otherplayerJSON.position[0], otherplayerJSON.position[1], otherplayerJSON.position[2]); Quaternion rotation = Quaternion.Euler(otherplayerJSON.rotation[0], otherplayerJSON.rotation[1], otherplayerJSON.rotation[2]); GameObject o = GameObject.Find(otherplayerJSON.pseudo) as GameObject; if (o != null) { Debug.Log(o); Debug.Log("this player exist already"); return; } Debug.Log("this player is new "); GameObject op = Instantiate(otherPlayer, position, rotation) as GameObject; // here we are setting up their other fields name and if they are local Player opC = op.GetComponent <Player>(); opC.pseudo = otherplayerJSON.pseudo; opC.Hscore = otherplayerJSON.Hscore; //var testr = op.GetComponent<UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController> (); //Debug.Log(testr); //testr.enabled = false; Transform ot = op.transform.Find("Canvas"); Transform ot1 = ot.transform.Find("pseudo"); Text oplayerName = ot1.GetComponent <Text>(); oplayerName.text = otherplayerJSON.pseudo; opC.isLocalPlayer = false; op.name = otherplayerJSON.pseudo; Debug.Log(opC.pseudo); Debug.Log(oplayerName.text); }
private void OnPlay(SocketIOEvent socketIOEvent) { string data = socketIOEvent.data.ToString(); Debug.Log("You joined: " + data); PlayerJSON playerJSON = PlayerJSON.CreateFromJSON(data); GameObject player = GameObject.Find(playerJSON.name); if (player != null) { Destroy(player); } player = SpawnManager.Instance.SpawnPlayer(playerJSON.name, playerJSON.position.ToVector3(), playerJSON.rotation.Euler()); PlayerController pc = player.GetComponent <PlayerController> (); pc.isLocalPlayer = true; CameraFollow.Instance.player = player; panel_Main.SetActive(false); }
public void OnOtherPlayerDisconnect(SocketIOEvent socketIOEvent) { string data = socketIOEvent.data.ToString(); PlayerJSON otherplayerJSON = PlayerJSON.CreateFromJSON(data); Debug.Log(otherplayerJSON.pseudo); Debug.Log(" want to disconnect"); GameObject test = GameObject.Find(otherplayerJSON.pseudo) as GameObject; if (test != null) { Debug.Log("this player exist and want to disconnect"); myscoreList.GetComponent <scoreList>().deleteScoreList(otherplayerJSON.pseudo); } else { Debug.Log("this player doesnt exist and want to disconnect"); } Destroy(GameObject.Find(otherplayerJSON.pseudo)); }