public message receiveDestroy(message m) { scObject foodInfo = m.getSCObject("foodInfo"); float x = foodInfo.getFloat("xPos"); float y = foodInfo.getFloat("yPos"); List <Connection> clients = Server.Instance.getClients(); for (int i = 0; i < clients.Count; i++) { Server.Instance.sendClientMessage(clients[i], m); } GameObject[] fs = GameObject.FindGameObjectsWithTag("food"); foreach (GameObject f in fs) { if (f.transform.position.x == x && f.transform.position.y == y) { Destroy(f); } } return(m); }
public void receiveDestroy(message m) { scObject foodInfo = m.getSCObject("foodInfo"); float x = foodInfo.getFloat("xPos"); float y = foodInfo.getFloat("yPos"); Debug.Log("get the destroy message"); GameObject[] fs = GameObject.FindGameObjectsWithTag("food"); foreach (GameObject f in fs) { if (f.transform.position.x == x && f.transform.position.y == y) { Destroy(f); } } }
public void scObjectToSnake(scObject s) { // unpack position of head Vector3 headPos = new Vector3(); headPos.x = s.getFloat("xPos"); headPos.y = s.getFloat("yPos"); headPos.z = s.getFloat("zPos"); transform.position = headPos; // unpack rotation of head Vector3 headRot = new Vector3(); headRot.x = s.getFloat("xRot"); headRot.y = s.getFloat("yRot"); headRot.z = s.getFloat("zRot"); transform.eulerAngles = headRot; // unpack segments int numSeg = s.getInt("segments"); if (numSeg < segments.Count) { foreach (GameObject go in segments) { Destroy(go); } segments.Clear(); } for (int i = 0; i < numSeg; i++) { Vector3 pos = new Vector3(); pos.x = s.getFloat(i + "_xPos"); pos.y = s.getFloat(i + "_yPos"); pos.z = s.getFloat(i + "_zPos"); if (i >= segments.Count) { GameObject newSegment = (GameObject)Instantiate(body, pos, Quaternion.identity); segments.Add(newSegment); } else { segments [i].transform.position = pos; } } }