Last active
August 29, 2015 14:21
-
-
Save grimmdev/6c2831dd9a68b121f6fb to your computer and use it in GitHub Desktop.
Using the Action Delegate and it's pretty sweet!
This file contains hidden or 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 UnityEngine; | |
using System; | |
using System.Collections; | |
public class ActionTest : MonoBehaviour { | |
// Use this for initialization | |
private void Awake () { | |
string url = "http://google.com"; | |
StartCoroutine(WaitForRequest(url,(status)=>{ | |
print(status.ToString()); | |
})); | |
} | |
private IEnumerator WaitForRequest(string url,Action<int> callback) | |
{ | |
WWW www = new WWW(url); | |
int tempInt = 0; | |
yield return www; | |
if (string.IsNullOrEmpty(www.error)) | |
{ | |
if(!string.IsNullOrEmpty(www.text)) | |
{ | |
tempInt = 3; | |
} | |
else | |
{ | |
tempInt=2; | |
} | |
} else { | |
print(www.error); | |
tempInt=1; | |
} | |
callback(tempInt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment