Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dialogue box over the character

Discussion in 'Scripting' started by shs2410, Aug 28, 2021.

  1. shs2410

    shs2410

    Joined:
    Jul 13, 2021
    Posts:
    15
    Is there a way I can make a dialogue box appear on top of a game object in a 3D game. I have tried using the canvas but that doesn't seem to work. I want it to appear as if it is floating over the game object.
     
  2. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    Hello,
    there are several approaches. You can use standard GameObjects, but managing the text would be a tad trickier.
    You can do it with canvas, by setting its Render Mode to World Space. You'd have to make sure it keeps facing the player.
     
    shs2410 likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,757
    This is the key, and this also usually this makes the box MASSIVE, like hundreds of units across, so I tend to make my WorldSpace canvases scaled down to 0.01 in all axes (X,Y,Z).

    Then as diXime pointed out, use a billboarding script to point it at the player, and parent it to the unit to keep it together.

    Attached is a handy start to making a dynamic UI that flows around arbitrary-sized text.

    To see it in world space, do these steps:

    - press PLAY
    - select the canvas
    - change it to World Space
    - change its scale to (0.01, 0.01, 0.01)
    - move its position to (0,0,0)

    It should be visible right there in your 3D world and you can pause and look around.
     

    Attached Files:

    shs2410 likes this.
  4. shs2410

    shs2410

    Joined:
    Jul 13, 2021
    Posts:
    15
    Thank you so much for the reply this works perfectly.
     
  5. shs2410

    shs2410

    Joined:
    Jul 13, 2021
    Posts:
    15
    Thank you. I implemented it and it works as intended.
     
    Kurt-Dekker likes this.