public void connectOrDisconnect() { if (!justStateChange && EasyWiFiController.clientState == EasyWiFiConstants.CURRENT_CLIENT_STATE.NotConnected) { //not connected currently so try to connect justStateChange = true; EasyWiFiController.checkForServer(); Invoke("resetDisconnection", 2f); } if (!justStateChange && EasyWiFiController.clientState == EasyWiFiConstants.CURRENT_CLIENT_STATE.SendingControllerData) { //connected currently so disconnect justStateChange = true; EasyWiFiController.sendDisconnect(EasyWiFiController.createDisconnectMessage()); Invoke("resetDisconnection", 2f); } }