Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do I open a link when clicking on text in Unity?

Discussion in 'Scripting' started by fstim82, Oct 21, 2011.

  1. fstim82

    fstim82

    Joined:
    May 4, 2010
    Posts:
    28
    I'm not sure where to start when it comes to opening up a browser/new tab. If I have text that is essentially a button, like any link you'd find online, how do I open up a browser and go to that URL when I click it?
     
  2. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    It's not supported out of the box. Best way to hack it in would be with an invisible button :)
     
  3. fstim82

    fstim82

    Joined:
    May 4, 2010
    Posts:
    28
    That's what I intended, my question is actually HOW to hack it in. It's not so much a Unity specific question as a general programming question. Once I've clicked my button, what do I do to open up a browser tab?
     
  4. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    this doesnt work?

    Code (csharp):
    1.  
    2. function OnMouseDown ()
    3. {
    4.     Application.OpenURL("http://www.webpage.com");
    5. }
    6.  
     
  5. fstim82

    fstim82

    Joined:
    May 4, 2010
    Posts:
    28
    LOL, I didn't think it would be anywhere near that easy. Thanks!
     
  6. Preisler

    Preisler

    Joined:
    Jan 19, 2017
    Posts:
    2
  7. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,135
    Just in case someone else stumbles upon this necro'd thread (seriously? three letters? that's a new record!), you can use Unity's latest acquisition - TextMesh Pro - to handle links in text.

    https://www.assetstore.unity3d.com/en/#!/content/84126

    By the way the OP hasn't been seen in four years. :p