Created
November 21, 2016 16:23
-
-
Save abeldantas/0d3ec6b8dc911a64c96625296c1fea91 to your computer and use it in GitHub Desktop.
Unity Toggle Pin ESP8266 NodeMCU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
public class TogglePin : MonoBehaviour | |
{ | |
private int index; | |
private string[] commands = new[] { "pin=ON1", "pin=OFF1" }; | |
public void Click() | |
{ | |
string url = "http://192.168.4.1?" + commands[index]; | |
WWW www = new WWW( url ); | |
StartCoroutine( WaitForRequest( www ) ); | |
index = index == 0 ? 1 : 0; | |
} | |
IEnumerator WaitForRequest( WWW www ) | |
{ | |
yield return www; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment