I am using C# and I would like my button to open a URL once it is clicked. How do I write this?
using UnityEngine;
using System.Collections;
public class OGSButton : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Application.OpenURL("http://unity3d.com/");
}
}
Is it a unity UI button?
If so you have to make a public void in your script, which opens the url, just like you did above.
If you want to activate the void on a button press you have to:
- go to the button.
- scroll to the bottom.
- where you see the onclick stuff, add the object that contains the object with your OGSButton and select the void that needs to be called.
Detailed tutorial here: Unity - UI Button