I'm building an application in Unity and I have a button that uses Application.OpenURL() to bring the user to a certain page when clicked. Up until now, I was using the fully typed out url name in double quotes as the parameter for the OpenURL function, and it was working as I intended. When I pressed the button the page was opened in the browser.
In order to incorporate multiple possible urls, I have changed the parameter to a string variable called url_name. Since this change, nothing happens when the same button is pressed. My code currently looks like this:
IEnumerator alertPopUp(string metaData_Content){
if (alertDelay)
{
yield return new WaitForSeconds (alertDelayLength);
}
string[] tokens = metaData_Content.Split (',');
string sign_name = tokens [0];
string url_name = tokens [1];
string template = "You discovered {0}";
string data = sign_name;
string message = string.Format(template, data);
MNPopup popup = new MNPopup ("Honorary Chicago", message);
popup.AddAction ("Find out more!", () => {Application.OpenURL(url_name);});
popup.AddAction ("Not now", () => {Debug.Log("action 2 action callback");});
popup.AddDismissListener (() => {Debug.Log("dismiss listener");});
popup.Show ();
}
Notes:
- The block that starts with MNPopup takes advantage of a plugin I got from the asset store that builds formatted pop ups. I don't believe it has anything to do with the problem, especially since the script worked as intended when I had a string typed out.
- I have tried testing with
Debug.Log(url_name)in place ofApplication.OpenURL(). The log displayed the correct url as intended, so it appears that url_name is the value I intend it to be.
Question:
Why is the Application.OpenURL() function working when I type out a string, yet not working when a string variable is inputted?