private void SpawnCrown(NetworkMessage netMsg) { GunfishMsg msg = netMsg.ReadMessage <GunfishMsg>(); Crowner.SpawnCrown(ClientScene.FindLocalObject(msg.netId)); print("Find Local: " + ClientScene.FindLocalObject(msg.netId)); }
public void RpcCrown() { if (!crowned) { crowned = true; Crowner.SpawnCrown(gameObject); } }
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { spawnPoints = FindObjectsOfType <NetworkStartPosition>(); //Get list of all spawn points in the scene //If there aren't any spawn points in the scene, spawn players at the origin Vector3 targetPosition = (spawnPoints.Length > 0 ? spawnPoints[(spawnNum) % spawnPoints.Length].transform.position : Vector3.zero); //Assign the players a random fish when they join int index = Random.Range(0, fishList.Count); if (RaceManager.instance.fishTable.ContainsKey(conn)) { index = RaceManager.instance.fishTable[conn]; } else { RaceManager.instance.fishTable.Add(conn, index); } GameObject player = (GameObject)Instantiate(fishList[index], targetPosition, Quaternion.identity); //print("PLAYER: " + player); string playerName = "Player " + (conn.connectionId + 1); if (RaceManager.instance && RaceManager.instance.pointTable.ContainsKey(conn)) { if (RaceManager.instance.pointTable[conn] > 0) { playerName += "\nPoints: " + RaceManager.instance.pointTable[conn]; if (RaceManager.instance.pointTable[conn] >= RaceManager.instance.MaxPointsEarned) { Crowner.SpawnCrown(player); } } else { Crowner.SpawnCrown(player); RaceManager.instance.pointTable[conn] = 0; } } NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); bool crowned = false; if (RaceManager.instance.pointTable.ContainsKey(conn) && RaceManager.instance.pointTable[conn] >= RaceManager.instance.MaxPointsEarned && RaceManager.instance.pointTable[conn] > 0) { crowned = true; } StartCoroutine(SetRpc(player, playerName, crowned)); ConnectionManager.instance.AddGunfish(player.GetComponent <Gunfish>()); spawnNum++; }
//When the Gunfish is started (server and client), assign fish info private void Start() { if (isServer || hasAuthority) { if (!rb) { rb = GetComponent <Rigidbody2D>(); } if (!gun) { gun = GetComponentInChildren <Gun>(); } gun.SetShotType(shotType); groundedCount = 0; currentJumpCD = 0f; currentFireCD = 0f; currentAirborneJumpCD = 0f; transform.eulerAngles = Vector3.forward * 180f; //Set the maxFireCD of the gunfish to the gun's maxFireCD. //Fire cooldown is handled here to avoid multiple nested //Network Transforms maxFireCD = gun.shotInfo.maxFireCD; if (hasAuthority) { PlayerController.ownedGunfish = this; } } middleRb = transform.GetChild((transform.childCount / 2) - 1).GetComponent <Rigidbody2D>(); GameObject nameplateObj = Instantiate(nameplatePrefab, transform.position, Quaternion.identity); nameplate = nameplateObj.GetComponent <NamePlate>(); nameplate.SetOwner(middleRb.gameObject); SetName(gameName); if (!SceneManager.GetActiveScene().name.Equals("RaceLobby")) { Stun(3f); } if (crowned) { Crowner.SpawnCrown(gameObject); } //Disable HingeJoints on all but the local player to //prevent weird desyncs in movement if (!hasAuthority) { rb.bodyType = RigidbodyType2D.Kinematic; foreach (Transform child in transform) { if (child.GetComponent <Rigidbody2D>()) { child.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic; } } } }