Forum rules - please read before posting.

Open Website in game?

Hello, is it possible to open a website within the adventure creator due a trigger or use function?

Comments

  • edited November 2021

    Custom script functions can be called from ActionLists using either the Object: Call event or Object: Send message Actions.

    This script, OpenLink.cs, can be used to open a link defined in its Inspector:

    using UnityEngine;
    
    public class OpenLink : MonoBehaviour
    {
    
        public string url;
    
        public void Interact ()
        {
            Application.OpenURL (url);
        }
    
    }
    

    To have it be triggered by AC, attach it to a GameObject in your scene, or a prefab, and use AC's Object: Send message Action to run its Interact function.

  • edited November 2021
  • edited November 2021

    I was inspired to try and make a custom action for opening a URL. Here's what I made:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
        [System.Serializable]
        public class ActionOpenURL : Action
        {
            // Declare variables here
            public string url;
    
            public ActionOpenURL()
            {
                this.isDisplayed = true;
                category = ActionCategory.Custom;
                title = "Open URL";
                description = "Opens a URL using Application.OpenURL()";
            }
    
            override public float Run ()
            {
                Application.OpenURL(url);
                Debug.Log("URL opened");
    
                return 0f;
            }
    
            #if UNITY_EDITOR
    
            override public void ShowGUI ()
            {
                // Action-specific Inspector GUI code her
                url = EditorGUILayout.TextField("URL to open:", url);
    
                AfterRunningOption ();
            }
            #endif
        }
    }
    

    This gives you an action you can then use in an action list:

    Note: Application.OpenURL() will open the website in your default web browser. It won't be in the game.

  • Really cool Thankyou!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.