//Update is called every frame. void Update() { long ms = m_Pelagia.MS(); while (true) { string msg = m_Pelagia.GetRec(); //Debug.Log(msg); if (msg == null || ((m_Pelagia.MS() - ms) >= 1000)) { return; } else { RecMsg rm = JsonUtility.FromJson <RecMsg>(msg); if (rm.cmd == "move") { NpcMove(rm.name, rm.d_x, rm.d_z); print("cmd move" + rm.name + " " + rm.d_x + " " + rm.d_z); } else if (rm.cmd == "init") { uint count = 0; GameObject gameObject1 = GameObject.Find("Cube"); for (int x = 0; x < MaxX; x++) { for (int z = 0; z < MaxZ; z++) { GameObject newobj = Instantiate(gameObject1, new Vector3(x, 0, z), Quaternion.identity); string key = "role" + (count++); name_obj[key] = newobj; InitMsg im = new InitMsg(); im.cmd = "create"; im.name = key; im.x = x; im.z = z; string json = JsonUtility.ToJson(im); m_Pelagia.Call("manager", json); } } } } } }
//Update is called every frame. void Update() { //Check that playersTurn or enemiesMoving or doingSetup are not currently true. if (doingSetup) { //If any of these are true, return and do not start MoveEnemies. return; } long ms = m_Pelagia.MS(); while (true) { string msg = m_Pelagia.GetRec(); //Debug.Log(msg); if (msg == null || ((m_Pelagia.MS() - ms) >= 1000)) { return; } else { RecMsg rm = JsonUtility.FromJson <RecMsg>(msg); if (rm.msg == "entry") { Entry(rm.npc); } else if (rm.msg == "play_move") { PlayMove(rm.npc, rm.sx, rm.sy, rm.x, rm.y); } else if (rm.msg == "play_attack") { PlayAttack(rm.id.ToString(), rm.x, rm.y, rm.hp, rm.target.ToString(), rm.del); } else if (rm.msg == "npc_attack") { NpcAttack(rm.id.ToString(), rm.target.ToString(), rm.hp); } else if (rm.msg == "npc_move") { NpcMove(rm.id.ToString(), rm.sx, rm.sy, rm.x, rm.y, rm.del); } } } }