How do i get a button in Unity to open a webpage?

  1. Create a UI button
  2. Create a new cSharp script called Loadingpage and open it in MonoDevelop
  3. Replace your script with the one below:

 


using UnityEngine;

using System.Collections;

public class Loadingpage : MonoBehaviour 

{
    public void Clicky (){
        Application.OpenURL(your web address here);
    }

}

 


Loading page and Clicky can be changed to what you like as long as they done clash with unity scripting words.

Copy and paste your full url between the ” ” marks inside the code. Then save the file.

with your button selected, drag and drop this script inside the inspector area on the right.

 

 

button script2

when you add new buttons you will automatically get a button script attached to it. This is a separate script that will refer to our own. it is not a visible script inside our assets folder. This script also lets you change the colour or the image on mouseover.

At the bottom of the button script you will see this area with a little plus sign, click on that.

Now where it says “none (Object)” click the little circle on the right hand side and choose the button you just created.

The drop down box that says “No Function” should now contain the name of your script, in this case its Loadingpage.

When you mouseover Loadingpage you should see Clicky(). Choose that.

And that is it!

your button should now open your webpage when you run.

If you create more buttons and want those to goto different pages, you can simply add more to the script, but make sure you choose the different clicky’s in the button script for each button.

 public void Clicky2 (){
        Application.OpenURL(another web address here);
    }

 public void Clicky3 (){
        Application.OpenURL(another web address here);
    }

ENJOY!