Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Last active August 29, 2015 14:21
Show Gist options
  • Save grimmdev/6c2831dd9a68b121f6fb to your computer and use it in GitHub Desktop.
Save grimmdev/6c2831dd9a68b121f6fb to your computer and use it in GitHub Desktop.
Using the Action Delegate and it's pretty sweet!
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