Forum rules - please read before posting.

Feature request: A Simpler way of adding variable output in UnityUI Text

Hello! I can't praise AC enough, it is such an amazing piece of software.

I would love to have an extra feature, tough.

Every time I need to display text coming from a variable value (for instance, a little disclaimer text, splash screen texts, end credits, and a long etc. that I need to show in the correct language), as far as I know, I need to use AC Menus to accomplish that.

The downside of it is that I have to create menus for that, then link to the Unity UI text that was already created, and then I need to manually set an actionlist to show/hide the new menu for instance in the scene I'm including the UI Text element.

I really think there could be a simpler way of doing that, maybe just by adding a "AC component" into the Text element? Or something that let us create a text box in a scene and have the ability to display values coming from variables.

I hope it makes sense. Thanks a lot for all the support!

Comments

  • edited February 14

    The easiest way to extract variable values is to reply on text tokens - i.e. [var:X], where X is the ID number of the variable.

    A string containing tokens can be converted into live values using the ConvertTokens function, so it's possible to display variables in Text box without the Menu Manager with a very short custom script:

    using UnityEngine;
    using UnityEngine.UI;
    
    public class TokenDisplayer : MonoBehaviour
    {
    
        public string inputText;
        public Text textBox;
    
        void Update() => textBox.text = AC.AdvGame.ConvertTokens(inputText);
    
    }
    
  • Thanks so much! In my humble opinion, this could come as part of AC as a component, it saves a lot of time and helps with maintainability! Now I can go and delete a lot of menus created just for the sake of putting any text on screen. Thanks again!!

    PS: Would there be a way of using it with Text Mesh Pro as well?

  • Ah! I figured how to do so:

    using UnityEngine;
    using TMPro;
    
    public class TokenDisplayer : MonoBehaviour
    {
    
        public string inputText;
        public TextMeshProUGUI textBox;
    
        void Update()
        {
            if (textBox != null)
                textBox.text = AC.AdvGame.ConvertTokens(inputText);
        }
    
    }
    

    Again, this is an incredibly easy to add feature that removes completely the need for using and controlling menus in cases we don't need them! Wonderful!!

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.