Render text inside Unity 2D speech bubble

Speech bubble

Hi, I am using Unity 2D to create a dialogue between two people. As you can see, I create a speech bubble when the character is dating someone. Then I want to have the text ("Hello, how are you?") From an external resource and whoever is inside it. Can anyone help me to do this? I don't know and I tried it with text grids but it didn't work. Thank you so much! (I am using Javascript)

+3


source to share


1 answer


To render text inside a speech bubble, you may need to use the so-called "new interface" that was introduced in Unity 4.6 and Unity 5. Don't go wrong with the legacy user interface system.

Documentation here , there are many tutorials (I would post links, but I don't have enough StackOverflow reputation).

Specifically, you will need an object in the scene with a Canvas (menu GameObject -> UI -> Canvas

) component , with Render Mode

(Canvas component inspector property) set to World Space

.

Then you can add a child object Image

via the menu GameObject -> UI -> Image

. This will contain the bubble image.



Finally, add a child to the object Image

via the menu GameObject -> UI -> Text

. This will contain the text "Hello, how are you", you can install it via some custom script of yours as soon as you take it from an external file.

To show / hide a bubble with text, just deactivate the whole object with gameObject.setActive(false)

(which will also disable the child text). I have a single script control that contains references to all UI objects (in this case Image

and Text

) and manipulates them as needed (activates / deactivates, sets text, changes image, etc.).

Admittedly, the new UI requires a bit of training and you will have to play around with different parameters for the best effect, but it can do what you ask.

+4


source







All Articles