void ProcessPacket(string text) { string[] results = text.Split(' '); if (results[0] == PACKET_SNAP.ToString()) { int playerID = Int32.Parse(results[1]); if (playerID != clientID) { GameObject dummyGO; if (!dummies.TryGetValue(playerID, out dummyGO)) { dummyGO = Instantiate(dummyPrefab, null); dummies.Add(playerID, dummyGO); } dummyGO.transform.position = new Vector3(float.Parse(results[2]), float.Parse(results[3]), float.Parse(results[4])); } } else if (results[0] == PACKET_HI.ToString()) { if (clientID < 0) { clientID = Int32.Parse(results[1]); Debug.Log("Received clientID! Setting it to" + results[1]); } else { // We already have a clientID. Send own one string message = PACKET_HI.ToString() + " " + clientID.ToString(); Debug.Log("HELLO> " + message); netCode.SendMessage(message); } } else if (results[0] == PACKET_SPWN.ToString()) { // Results 1,2,3 are Position.XYZ Vector3 position = new Vector3(float.Parse(results[1]), float.Parse(results[2]), float.Parse(results[3])); // Results 4,5,6,7 are Rotation.XYZW Quaternion rotation = new Quaternion(float.Parse(results[4]), float.Parse(results[5]), float.Parse(results[6]), float.Parse(results[7])); Instantiate(bulletPrefab, position, rotation, null); } else { //Debug.Log(packetType + "!=" + PACKET_SNAP.ToString()); } }
public void Initiate() { netCode = new NetCode(ipAddress, port); UInt16 packetType = PACKET_HI; netCode.SendMessage(packetType.ToString()); Debug.Log(PACKET_ACK + " " + PACKET_BYE + " " + PACKET_SNAP + " " + PACKET_HIT + " " + PACKET_HI + " " + PACKET_SPWN); isStarted = true; }