Author Topic: Launch URL in browser upon Click of a label with a button & script attached fail  (Read 4387 times)

jtok4j

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Well, I hope the subject wasn't too annoying.

 I've just switched to NGUI, and wow, what a life-saver. (Helping me get the GUI done about 4x as fast as previously hacking away at the )*EELJK  GUI in Unity 4.3...

 Anyway, I've got a label in my menus which has a box collider and a UIbutton (script) attached to it.  It looks great!
 I've also attached a script of my own to the label, which (in my other projects works & ) launches a web browser and opens the URL that I want to open.

 But I cannot seem to get this script to launch the browser and open the url, when clicking on this label.

 If it helps, here's the code in the script. Usually it's just attached to a game object (without NGUI) and when you click that game object, it opens the link in a browser:
 
 public class MoreGamesLink : MonoBehaviour {

   void openMoreGameLink(){
            if (Input.GetMouseButtonDown (0)) {
                  Application.OpenURL ("http://bitofgame.com/web/quad-king.html");
            }
      }
}


 So, I've searched the NGUI forums and Unity Answers, but there's no specific help on this.  I mean, clicking a game object and getting a web browser to launch with your desired url is fairly simple, but I cannot seem to get it to work, with the above setup.

 I've also used the openurlonclick script instead of my own, with the label, but that also does absolutely nothing as well.

 Anything that I'm doing wrong ?    Thanks for any obvious or not-so-obvious pointers you can direct me with.  :D
 

jtok4j

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Well,

 In a rather embarrassing trial and error session, I've realized that the code needs to be adjusted to this:

 (Line from the openurlonclick.cs script)

 Was: if (!string.IsNullOrEmpty(url)) Application.OpenURL("http://webdomain.com/");


 Had to change it to:

 if (string.IsNullOrEmpty(url)) Application.OpenURL("http://webdomain.com/");


 It works like a charm now, with the web browser launching and the URL loading successfully. :)

 Hopefully this will help someone else!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
The line in the OpenURLOnClick is not hardcoded:
  1. if (!string.IsNullOrEmpty(url)) Application.OpenURL(url);
...which is why that statement makes sense.

jtok4j

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Thank-you, ArenMook  :)