1

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 of Application.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?

2
  • 1
    Do you have some example data that is logged when you construct it, and when you type manually? Make sure the constructed URL starts with the protocol schema and otherwise follows the URL format correctly
    – Kroltan
    Jul 11, 2017 at 16:27
  • @Kroltan Could you explain what you mean by example data? And the constructed URL is the full, formatted URL
    – Luke
    Jul 11, 2017 at 16:34

1 Answer 1

1

I had this problem. In my case it was caused by a newline character at the end of the variable strings. In a similar case - try url_name.Trim() Maybe a bit late for you, but it may help someone else...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.