Would it be possible in a future version of AC to have a new "Link" menu element that would allow players to click on it to open a provided link in a web browser? It could also be a Label element with a label type of link.
The element would have a text label (displayed in the menu, as for label element) and a url property (address to open in the browser). It would call Application.OpenURL ("URL");
Comments
The current Button element can be set to run an ActionList (in which a custom Action can open the link), or run a custom script (using the OnMenuElementClick event). Both of these would allow for the OpenURL method call to be made.
Making a new custom Action for this is very simple. Follow the tutorial (and see the "ActionTemplate" file), then place the method call inside your Action's Run() method, followed by "return 0f;".
The code is hereafter. To use it, you need to copy the code into a file (I used LinkFollow.cs), copy the file into the directory you use for custom actions (as defined under "Custom action scripts" on AC's Action menu tab).
After doing this, you should have a new custom action which you can use in ActionLists: in the action box, select Custom : Link. This allows you to specify a URL to jump to or to use one contained in a global variable.
To use this from a menu button for example, in the button's "ActionList to run" field, specify an ActionList which contains this new custom action.
I get the following error code when trying to use this. Any suggestions what to change to fix?
Have you installed it in the correct way, as outlined in this tutorial? Is it listed in the Actions Manager?
Sometimes restarting Unity can resolve this.
Installed as instructed, but wasn't working until rebooting machine and not just reloading Unity. One of those weird PC moments. Thanks, now works excellent!
Am I right to assume that this script needs to be updated to work under 1.72.4?
And what would have to be changed to make it accept all kinds of variables instead of only Global Vars (plus parameters), too?
The only issue I can see is the need to change:
with:
You can define and expose a VariableLocation enum variable to let the user choose between Global and Local, and then call LocalVariables.GetVariable depending.
Parameters are an extra complication, but a series of tutorials on writing custom Actions (that concludes with the introduction of parameters) can be found here.
Yes, right. And parameters are already included, too.
I just would have liked to let the script access Component Variables, but I couldn't get it to work.
Unfortunately I cannot get this to work with the option "Copied from Global Variable".
The problem is that "Copied from Global Variable" doesn't copy … I suspect it doesn't do anything in fact.
It's a pity because this custom action would be a great addition!
Works for me. Here's a more cleanly-formatted script:
So, I've followed the instructions listed here and on that tutorial. I've created the new custom action and its showing up in the editor, I can type out a link, but for some reason no page is being opened up. Any ideas what I'm doing wrong?
The above script actually has the link-opening commented out. Replace:
with:
Ok, I've done that now, but now I'm getting this error:
https://ibb.co/7yzsKP0
That's not coming from AC - and not Unity by the looks of it.
The AC side of things is just providing a means to call the above line - you'll need to consult Unity's documentation on it for guidance:
https://docs.unity3d.com/ScriptReference/Application.OpenURL.html
Ok, thanks.