Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] Application.OpenURL Issues

Discussion in 'Scripting' started by GeneralDollar, Jun 19, 2018.

  1. GeneralDollar

    GeneralDollar

    Joined:
    Mar 24, 2018
    Posts:
    27
    Whenever I click the button with this script on it, it opens the URL in a web browser while simultaneously opening a file explorer window. Why is this happening, and how can I prevent this.

    Code (csharp):
    1.             if (Input.GetMouseButtonDown(0))
    2.             {
    3.                 RaycastHit hit;
    4.                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    5.  
    6.                 if (Physics.Raycast(ray, out hit))
    7.                 {
    8.  
    9.                     btnName = hit.transform.name;
    10.                     switch (btnName)
    11.                     {
    12.                         case "Button1":
    13.                             Application.OpenURL(urlITunes);
    14.                             break;
    15.                         case "Button2":
    16.                             Application.OpenURL(urlWebsite);
    17.                             break;
    18.                         case "Button3":
    19.                             Application.OpenURL(urlFacebook);
    20.                             break;
    21.                         default:
    22.                             break;
    23.  
    24.                     }
    25.                 }
    26.  
    27.  
    28.             }
    Thanks!
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    If these are UI buttons, you could have just set up the button clicks in the onClick event. Would be easier than doing a raycast.

    But, as far as your issue. I don't see one with what you posted, but there is not enough information. Assuming your openurl calls have web links only, not sure why you would get anything else opening with it.
     
    GeneralDollar likes this.
  3. GeneralDollar

    GeneralDollar

    Joined:
    Mar 24, 2018
    Posts:
    27
    That's why I am extremely confused. There is really nothing more to the script than what I have showed. Just the URL links. Yet every time I click the button, it opens the web browser as expected and a file explorer window which is not expected.

    If this makes a difference, it opens the file explorer window up to the exact location that the project is saved. Every time.

    Thanks for any help!
     
  4. GeneralDollar

    GeneralDollar

    Joined:
    Mar 24, 2018
    Posts:
    27
    I figured it out. I had extra buttons attached to separate assets that had no URL's linked, and would by default open up a file explorer window. Definitely a beginner mistake, which I am a beginner lol

    Thanks!