How to change text displaying button names after it's already displayed?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
wedgiebee
Posts: 16
Joined: Wed May 25, 2022 6:40 pm

How to change text displaying button names after it's already displayed?

Post by wedgiebee »

Hi, I'm starting to make some Tutorial/Controls instructions with Dialogue System and I've got a couple questions.

1) I want to have a dialogue that says either "Use WASD to run" or "Move the left stick to run" depending on if the player is on a controller or a keyboard. I detect this by seeing if the last player input came from a keyboard or a controller. BUT if the player presses a different input WHILE the dialogue is showing (ex. the've been using a controller, dialogue says "Use WASD to run", but then they press a keyboard key), I want the text to update to show the tutorial text that's relevant for a keyboard. What's the best way to do that?

2) I also want to pop up a prefab of a controls diagram I made. Not an in-line icon, but a separate controls diagram that I would show above the dialog box. And it would be a separate diagram for keyboard or controller. Is there a way to do that?

Thanks for your help!!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to change text displaying button names after it's already displayed?

Post by Tony Li »

Hi,
wedgiebee wrote: Wed May 31, 2023 2:51 pm1) I want to have a dialogue that says either "Use WASD to run" or "Move the left stick to run" depending on if the player is on a controller or a keyboard. I detect this by seeing if the last player input came from a keyboard or a controller. BUT if the player presses a different input WHILE the dialogue is showing (ex. the've been using a controller, dialogue says "Use WASD to run", but then they press a keyboard key), I want the text to update to show the tutorial text that's relevant for a keyboard. What's the best way to do that?
Hook into the UnityEvents InputDeviceManager.instance.onUseKeyboard, .onUseJoystick, and .onUseMouse to know when the player has changed input devices. You could point all of them to the same method, and in that method check InputDeviceManager.instance.inputDevice. Then do a few more things in the method:

1. Set a Dialogue System variable, such as:

Code: Select all

DialogueLua.SetVariable("InputDevice", "Joystick");
2. Change the currently-displayed subtitle text using code similar to: How To: Update Currently-Displayed Text When Changing Language. You could define variables in your database such as:
  • Run_Joystick = "Move the left stick to run"
  • Run_Keyboard = "Use WASD to run"
Then set your Dialogue Text to:
  • Dialogue Text: [var=Run_[var=InputDevice]]
3. Change the pop up prefab (below).

wedgiebee wrote: Wed May 31, 2023 2:51 pm2) I also want to pop up a prefab of a controls diagram I made. Not an in-line icon, but a separate controls diagram that I would show above the dialog box. And it would be a separate diagram for keyboard or controller. Is there a way to do that?
You could put the prefabs in your scene or dialogue UI and set them inactive. Then use the SetActive() sequencer command to activate the appropriate one. For example, say you've named the joystick prefab "Joystick_Controls". Then you could use this sequencer command:

Code: Select all

SetActive([var=InputDevice]_Controls)
wedgiebee
Posts: 16
Joined: Wed May 25, 2022 6:40 pm

Re: How to change text displaying button names after it's already displayed?

Post by wedgiebee »

Finally got around to implementing this, and it worked great! Thank you so much!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to change text displaying button names after it's already displayed?

Post by Tony Li »

Glad to help!
Post Reply