Forum rules - please read before posting.

Text Prompt GUI

Hi!

I'm trying to get a "Text Prompt" working in my game. What I mean, is basically a GUI with a label that pauses the game until player clicks on button to continue. Ideally, I should be able to "stack" them one after another so: GUI with text pops up, you click a button which makes the GUI disappear, and then another GUI appears but with updated text.

I've managed to get a GUI with string to show, it's just the "stacking up" that's the problem.

I've created an ActionList with string parameter, so I can call it like this:

The ActionList called TextPrompt looks like this:

It basically swaps out a global string that's later linked to the label on GUI resulting in turning on a GUI with the entered text.

The problem starts when I want to have one of these actions after another, so that each message will display after clicking the button.

I've tried something like this, but that just ends up breaking the whole Unity project.

Ideally what would happen, is that the first PromptText ActionList would wait until the main menu is invisible (clicking on the GUI button turns of the GUI) and then run another PromptText ActionList.

I hope this make sense. Is there some trick I'm missing? I feel like there's an easy way to achieve what I want, but I just can't seem to find it. Any help is greatly appreciated!

Comments

  • I think you're on the right track - your first attempt at "TextPrompt" will end as soon as the Menu turns on, causing the next ActionList: Run Action to run.

    Try giving your wait time a small value, e.g. 0.1s. If the menu pauses the game, however, I'm not sure it'll work as intended.

    What may be the better option would be to create a "callback" system, so that the command to run the next prompt comes from the menu being turned off, i.e. its ActionList when turn off field. You could use a variable to dictate what happens exactly when the menu is turned off.

  • Thanks for the reply!

    Changing the wait time value to 0.1 doesn't crash Unity, but it's not allowing me to click on the GUI button. All animations and sounds keep playing, but it's resulting in getting stuck with GUI constantly visible and not being able to proceed.

    The only way I've managed to get it to work is by removing the Wait Action, but instead checking Pause game when enabled on the GUI. It does what I need, but also does other things which are not ideal: it removes any other GUI that I may have currently on the screen and (as name suggests) it pauses the game, so all sound and animations are paused.

    I've also tried setting up additional actions after GUI is turned off, as suggested, but it resulted in displaying one, very specific "TextPrompt" that was set after GUI is turned off - I can't seem to find a way to allow me to trigger correct "TextPrompts" in order.

    I'm guessing to get optimal results, I would need to create a custom script for an Action to display the GUI?

  • The only way I've managed to get it to work is by removing the Wait Action, but instead checking Pause game when enabled on the GUI. It does what I need, but also does other things which are not ideal: it removes any other GUI that I may have currently on the screen and (as name suggests) it pauses the game, so all sound and animations are paused.

    The Sound and Animator components should offer controls to allow for playback while the game is paused (Play while game paused? and Unscaled Time respectively).

    I've also tried setting up additional actions after GUI is turned off, as suggested, but it resulted in displaying one, very specific "TextPrompt" that was set after GUI is turned off - I can't seem to find a way to allow me to trigger correct "TextPrompts" in order.

    I don't know what your ActionList logic is set to, but it should be possible through the use of variables.

    I'm guessing to get optimal results, I would need to create a custom script for an Action to display the GUI?

    It sounds like what you really need is just a custom Action that turns a menu on but also waits until it's turned off.

    Turning a menu on is just a matter of calling:

    PlayerMenus.GetMenuWithName ("MyMenu").TurnOn ();
    

    And checking if it's still on or not:

    if (PlayerMenus.GetMenuWithName ("MyMenu")).IsOn () { // Wait }
    

    See the ActionTemplate.cs file for comments on how to have an Action wait until a process is completed.

  • Thanks for the tips. I've created a custom action and tried to follow the comments on how to make an action wait until the process is complete.

    The idea is that the action keeps running until you turn off the GUI by clicking on it's button. Here's the action's Run code:

    override public float Run()
            {
                PlayerMenus.GetMenuWithName("Text Prompt").TurnOn();
    
                if (PlayerMenus.GetMenuWithName("Text Prompt").IsOn())
                {
                    isRunning = true;
                    return defaultPauseTime;
                }
                else
                {
                    isRunning = false;
                    return 0f;
                }
            }
    

    The above makes the animations and sound run as normal and it looks like it doesn't allow to run any other actions after this one (which is a desired result). Except that... the cursor turns into the waiting icon and it doesn't process any clicks, making the game wait forever.

    I also tested placing this action in "Run in the background" ActionList but it doesn't seem to make any difference.

    Ideally what would happen is the same as above, but the action needs to allow me to click, so that I can turn off the GUI and eventually run another action afterwards, but I can't seem to find a way to do this.

  • What's your Menu's Appear type? set to? Unless you check Clickable in cutscenes? in its properties, the ActionList will indeed have to run in the background.

    If the Menu pauses the game, try unchecking Can unfreeze 'pause' Menus? in the ActionList asset's Inspector.

  • Thank you!
    Appear type? is set to Manual. I checked the Clickable in cutscenes? and combined with some variables it seemed to do the trick!

    I've basically set a Global Integer that keeps the track if menu is on/off or if you clicked it or not.

    In case someone finds it useful:

    override public float Run ()
            {
                if (AC.GlobalVariables.GetIntegerValue(48) == 0) // Global Variable tracks what happens with the menu
                {
                    AC.GlobalVariables.SetStringValue(20, text); // Allows to change the text on Text Prompt Menu
                    PlayerMenus.GetMenuWithName("Text Prompt").TurnOn();
    
                    AC.GlobalVariables.SetIntegerValue(48, 1);
                }
    
                if (AC.GlobalVariables.GetIntegerValue(48) == 1)
                {
                    isRunning = true;
                    return defaultPauseTime;
                }
                else if (AC.GlobalVariables.GetIntegerValue(48) == 2) // Clicking on GUI has an ActionList when turn off, which sets the integer to 2
                {
                    isRunning = false;
                    AC.GlobalVariables.SetIntegerValue(48, 0);
                    return 0f;
                }
                else
                {
                    Debug.LogError("Text Prompt GUI ERROR");
                    return 0f;
                }
            }
    

    A tiny problem I still have is that I can't seem to get the text in the Unity GUI (ActionList) to wrap. Basically in this Action you can pass a text that will show in the Text Prompt Menu, but it doesn't want to wrap:

    override public void ShowGUI ()
            {
                // Action-specific Inspector GUI code here
                GUIStyle myText = new GUIStyle(EditorStyles.textField);
                myText.wordWrap = true;
    
                text = EditorGUILayout.TextField("Text to Display:", text, myText, GUILayout.MaxWidth(400f));
    
    
                AfterRunningOption ();
            }
    

    Is there something specific I need to set because it's AC related?

  • Is there something specific I need to set because it's AC related?

    Shouldn't be - you're still using Unity's provided Editor GUI system.

    Try:

    EditorStyles.textField.wordWrap = true;
    
  • Okay, I've got this and everything works well!

    I think I was using EditorGUILayout.TextField and it should have been EditorGUILayout.TextArea instead.

    Anyways, here's the full thing if anyone finds it useful (I ended up re-using the code from ActionSpeech, which did the trick)!

    override public void ShowGUI ()
            {
                // Action-specific Inspector GUI code here
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Text:", GUILayout.Width(65f));
                EditorStyles.textField.wordWrap = true;
                text = EditorGUILayout.TextArea(text, GUILayout.MaxWidth(400f));
                EditorGUILayout.EndHorizontal();
    
                AfterRunningOption ();
            }
    
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.