public void UpdateHHOnPoints() { JSONObject jo = new JSONObject(); jo.AddField("playerId", playerId); jo.AddField("points", myPoints); ControllerMessage cm = new ControllerMessage(0, 1, "score", jo); //sender.SendToListeners("score", "playerId", playerId, "points", myPoints.ToString(), 1); sender.SendToListeners(cm); }
public IEnumerator ExecuteDisablePlayersPowerUp(Player play) { play.myPoints++; play.UpdateHHOnPoints(); theNonPlayerId = play.playerId; Debug.Log("the players id: " + theNonPlayerId); //disable players for a little sender.SendToListeners("disabled", "playerId", theNonPlayerId, 1); //immune player foreach (Player ply in playerList) { if (ply.playerId != theNonPlayerId) { ply.listener.Remove(ply.movementListener); ply.listener.Remove(ply.jumpingListener); } } //disables for 5 seconds Debug.LogError("disabled"); yield return(new WaitForSeconds(5.0f)); Debug.LogError("should be enabled"); //send re-enable message to players sender.SendToListeners("enabled", "playerId", theNonPlayerId, 1); foreach (Player ply in playerList) { Debug.Log("trying to add listeners"); if (ply.playerId != theNonPlayerId) { ply.listener.Add(ply.movementListener); ply.listener.Add(ply.jumpingListener); } } yield return(new WaitForSeconds(0.1f)); }
void OnCollisionEnter(Collision col) { float speed = rb.velocity.magnitude; health -= speed; sender.SendToListeners("health", "health", health, playerIndex); if (health <= 0.0f) { Instantiate(explosionPrefab, transform.position, transform.rotation); Destroy(gameObject); } if (col.gameObject.CompareTag("Bullet")) { health -= col.gameObject.GetComponent <Bullet>().damage; } }