Forum rules - please read before posting.

How to display my replacement token within Unity UI

Hi, apologies if this question is a little confusing. I'm a new to the game creation world and I've LOVED my experience with Adventure Creator so far!
Right now I am creating a SMS replica type game and I need to find a way to attach my [ var:0] (Player Input Name) to a dragable image I have created in Unity UI. Is there any way I can attach a menu or dialogue to this object? I see there is a Position: On Hotspot option under the menu manager which could work since I can successfully add a hotspot to this Image. If not, is there a workaround to have a personalized name that I can add to UI > Text. Thank you and please let me know if you need more information! (pictures included).

Images:
https://ibb.co/27xLWxL
https://ibb.co/z2rPWTL

Comments

  • edited May 2020

    Welcome to the community, @hwinstead19.

    There's two ways to do this, depending on your preference:

    1) Hook up the UI Canvas to AC's Menu Manager, and then connect the Text component to a Label element. This allows AC to control its contents at runtime, which means it can automatically convert token text.

    To avoid confusion about the Hotspot: the "Position type: On Hotspot" setting has no effect on a Menu's contents - only where it is placed. This setting will cause it to appear over the currently selected Hotspot in the scene - you shouldn't attach a Hotspot component directly to the UI itself.

    Best to start out by creating a regular "Adventure Creator" menu (i.e. one that doesn't use Unity UI) to get the behaviour you're looking for. Don't worry about its appearance too much at this stage: just use the basic controls to get it showing the right text in the right place. If you create a Label element, you can enter the token into its own "Label text" field, and that will be converted correctly at runtime.

    Once the behaviour is correct, you can then go about switching it to Unity UI. A tutorial on this topic can be found here. It also looks like you might be using Text Mesh Pro, in which case you'll have to tell AC that it can make use of it. For more details, see the Manual's "Supported third-party assets" chapter.

    2) It's also possible to avoid AC's Menu system entirely should you choose, and just rely on a simple script to update the text manually. If you're dealing with a regular Unity Text component, attaching the following should do it:

    using UnityEngine;
    
    public class ConvertACToken : MonoBehaviour
    {
    
        public string textToDisplay = "[var:0]";
    
        void Update ()
        {
            GetComponent <UnityEngine.UI.Text>().text = AC.AdvGame.ConvertTokens (textToDisplay);
        }
    
    }
    
  • @ChrisIceBox Great! Thank you so much for your quick response. If I was to manipulate the script, would I go to the would I go to Object > Text (not TMP) then > add component > Simple Script and add this to the C# provided to me? Thanks again!

  • The script I provided should be named ConvertACToken.cs - it needs to match the class name.

    But yes, once done you can choose "Add component" then "Convert AC Token" - or just drag it over from the Project window directly.

  • Thank you so much Chris!

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.