How to Create Floating Text with Unity: A step-by-step tutorial

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 51

  • @jonbednez
    @jonbednez  2 роки тому +3

    Do you use floating text in your game? What kind of font looks best? Is there a color or effect that helps them stand out more?

  • @stormbread5096
    @stormbread5096 Місяць тому +2

    Thank you so much for the tutorial!!!! People like you who make tutorials like this are absolute heroes!!!!

    • @jonbednez
      @jonbednez  Місяць тому +1

      Thanks for watching! I'm glad you found this helpful.

  • @friszld
    @friszld Рік тому +4

    Thank you! This is simple and straightforward. Only suggestion would be to move your face cam on the screen to somewhere where it doesn’t cover the inspector as much. Thanks again 🙏🏻

    • @jonbednez
      @jonbednez  Рік тому +1

      thanks for the tip! im always looking to grow and adapt. this is helpful. glad u found this tutorial useful

  • @PantsOnLava
    @PantsOnLava Рік тому +12

    Thank you! and here's the script for everyone. Don't forget to manually assign the variables, i set them all as public.
    using UnityEngine;
    using UnityEngine.UI;
    public class UIFollow3DObject :MonoBehaviour
    {
    public Transform mainCam;
    public Transform target;
    public Transform worldSpaceCanvas;
    public Vector3 offset;
    private void Start ()
    {
    mainCam = Camera.main.transform;
    transform.SetParent(worldSpaceCanvas);
    }
    void Update ()
    {
    transform.rotation = Quaternion.LookRotation(transform.position - mainCam.transform.position); // look at camera
    transform.position = target.position + offset;
    }
    }

    • @jonbednez
      @jonbednez  Рік тому

      Awesome! Are you implementing this or similar script into your game / app?

    • @TheosResearchDiary
      @TheosResearchDiary Рік тому +1

      Thanks so much. The video is only 720 so this is way nicer than following along. Any change you could explain how to manually assign the variables? I'm super new at this.

    • @jonbednez
      @jonbednez  Рік тому +1

      @@TheosResearchDiary Hey Thoreau! To manually assign variables, you can click, hold and drag the corresponding objects from the scene window onto the script’s variables in the inspector window.

    • @jonbednez
      @jonbednez  Рік тому

      @@TheosResearchDiary For the camera variable, find the camera in your scene. Click, hold and drag the camera to the mainCam variable on the Floating Text script in the inspector. With the target, you can do the same action with a game object in the scene ( what are you using? ). The canvas variable can be assigned by finding the Canvas in the scene that uses the World Space render mode. Drag and drop that object onto the script in the inspector. Is this what you are looking for? Thank you for checking out the channel!

    • @TheosResearchDiary
      @TheosResearchDiary Рік тому +1

      @@jonbednez Thanks so much Jon! and for the great video. I haven't implemented anything yet but be sure to post and link to your channel when my team does. (small class project)

  • @windy-autumn
    @windy-autumn 9 місяців тому

    That's what we need! Great tutorial!! Thank you so much! Keep it up! 😁👍

    • @jonbednez
      @jonbednez  9 місяців тому +1

      Thanks, will do!

  • @storyofhitsuji579
    @storyofhitsuji579 7 місяців тому +2

    hello, first of all I would like to thank you for the tutorial, it is very helpful. So I experienced a little problem, yesterday after I tried your tutorial it worked, then after I opened the project a problem occurred, namely the text didn't appear when playing and in the hierarchy the text seemed to disappear. So where do you think the problem is?

    • @jonbednez
      @jonbednez  7 місяців тому

      hello! does the text disappear during runtime only? the text should parent itself to the world space camera at runtime, so its visible. could it be font or font size? is the width of the text box too small? are you using a world space canvas?

  • @whiskers1560
    @whiskers1560 Рік тому +2

    Thanks dude!

    • @jonbednez
      @jonbednez  Рік тому

      No problem! Glad u found this helpful.

  • @adixtin7920
    @adixtin7920 Рік тому +2

    Thank you. this video helped a lot. but one issue that u could easily fix is setting the font of cisual studio as a bigger. have a nice day:)

    • @jonbednez
      @jonbednez  Рік тому

      np. thank you for the helpful advice! I'll make those changes for future videos. glad you found this helpful. have a great day as well.

  • @parallel_53
    @parallel_53 Рік тому +2

    Maybe put your webcam overlay on the left bottom corner, since a few times you performed mouse and data entry actions that were actually obscured by your webcam frame.

    • @jonbednez
      @jonbednez  Рік тому

      ah good catch! I recently got a green screen, I'm hoping that also helps for future vids. I'll keep an eye on the overlay. Thanks for the advice! Did you find the code useful?

    • @parallel_53
      @parallel_53 Рік тому +1

      @@jonbednez Yeah was well put together, short and concise.

  • @emz6133
    @emz6133 6 місяців тому +1

    I saw a guy in another tutorial making one world space canvas for each character in the game, and making it a child of that character's game object, and you are using one canvas for all name tags in the game. He doesn't need to calculate the text's position since it's the child of the character GO and moves with it automatically, but it's not a hassle to move the text manually as you do. Is there any difference in having a single canvas for all name tags or one canvas for each? What is the better approach? If there are hundreds of characters with name tags in a scene, would creating hundreds of small canvases affect performance?

    • @jonbednez
      @jonbednez  6 місяців тому

      good question. I would look at the profiler. my solution is an alternate solution. multiple canvases is probably best practice. I found some useful answers to your question ➤ community.gamedev.tv/t/multiple-canvases-is-recommended-by-unity/198288 and ➤ stackoverflow.com/questions/74699735/what-are-the-performance-implications-of-using-multiple-world-space-ui-canvases. have a great weekend! and thanks for checking out the content. cheers.

  • @emz6133
    @emz6133 6 місяців тому +1

    Is there any difference in using "Text - Legacy" and "Text - TextMeshPro" for the name tag?

    • @jonbednez
      @jonbednez  6 місяців тому

      hey! tbh. I don't use much of TextMeshPro, so I can't speak to that.

  • @nikson12gg
    @nikson12gg 4 місяці тому +1

    Isn't using texts or images without canvas more performance-friendly? And instead of LookRotation() method shouldn't we use text.forward = camera.forward? And instead of adjusting text's position by our hand, shouldn't we do it by code which calculates collider's bound size and would work for any size of object? Idk, these are my ideas

    • @jonbednez
      @jonbednez  4 місяці тому +1

      great ideas! are you referring to Sprites, 3d text, Raw Images? If you are experiencing performance issues, I would check the profiler. I’m not sure in terms of performance, probably depends on the amount of floating text you have rendering at one time. LookRotation is a preference. Yea, we could calculate collider bounds for y position. That’s why I love coding. Lots of various solutions. Thanks for watching.

    • @nikson12gg
      @nikson12gg 4 місяці тому

      ​@@jonbednez The reason I chose Unity over Unreal is its simplicity. I don't care much for Unreal's graphics, but Unity's simplicity comes at the cost of not having as good performance as Unreal. So, I always try my best to maximize my game's performance. I have no performance issues, as I get about 400 FPS, but I still want my game to be playable on weaker PCs as well.
      I'm using sprites for the health bar and TextMeshPro for the names, and in my game, where we look at objects from above, the camera never rotates (like in Kingsroad). So, I don't have to use the look-at-camera method for them.
      I'm also using object pooling for damage texts. Again, no performance issues, but still trying my best to have as good performance as possible

    • @jonbednez
      @jonbednez  4 місяці тому

      @@nikson12gg ok that makes sense. all good points. Object pooling is a great idea, especially if you have 1000s of objects. ok, I see why you asked about the world space canvas, you are using sprites instead. I think it really depends on how much UI you have displayed at one time. I use the overlay canvas for my UI buttons and world space for the floating text. I probably have about 20 health bars / floating text at one time. What kind of game are you making? I'm available if you ever need someone to test / playthrough, etc.

    • @nikson12gg
      @nikson12gg 4 місяці тому

      @@jonbednez thank you so much for your interest, but I'm developing my game very slowly and there is not much things to see yet. Do you know Kingsroad? That game was epic, bat sadly they shut down for some reason. I'm very into rpg games and Kingsroad was like it. Kingsroad wasn't open-world, we were just moving to new scenes(always teleporting instead of moving kilometers by foot like in open worlds). I would like creating a game like Kingsroad and I know my knowledge yes it very small for that, but step by step I learn things. I'm a new developer so I need time

    • @jonbednez
      @jonbednez  4 місяці тому +1

      @@nikson12gg No problem. I've never played Kingsroad. I was just looking it up, reminds me of Diablo. Back in the day, I used to play flash games on Newgrounds / Kongregate. Looks like it was a fun game. I'm reading it moved to mobile IOS/Android? Anyway, I'm always trying to learn new things too, still working on a game myself. Thanks for the feedback. Good luck!

  • @justpablo9509
    @justpablo9509 Рік тому +2

    i have the problem that the text is behind my transparent object. Is there a way to fix this?

    • @jonbednez
      @jonbednez  Рік тому +1

      Hi justpablo! In trying to help solve what's happening, I have some questions for you. :) 1. Are you modifying the floating text offset (It could be the Z Vector)? 2. Is the floating text under the World Space Canvas in the hierarchy? 3. If you look at the World Space Canvas, what is the Order in Layer number (the higher the number - the more priority)? 4. Are you using a Unity Standard Transparent Shader or is this a Custom Shader? 5. The transparent object -> Is this a gameobject in the scene? Thanks!

  • @smokeyasmr
    @smokeyasmr 3 місяці тому

    how do i remove the text if the player object is destroyed?

    • @jonbednez
      @jonbednez  3 місяці тому

      hey! in the beginning of the Update() function of the Floating Text script. you could add a check to see if the target exists. You can destroy the gameobject or use object pooling.
      void Update ()
      {
      //check if target exists, if not, remove from scene
      if(target == null)
      {
      Destroy(this.gameObject);
      return;
      }
      transform.rotation = Quaternion.LookRotation(transform.position - mainCam.transform.position); // look at camera
      transform.position = target.position + offset;
      }
      If you want an alternative to destroying, you could try object pooling as an alternative. Here is the tutorial ➤ ua-cam.com/video/HnyaCNw6quM/v-deo.htmlsi=lTcHkmscGvQkU8JT
      Cheers.

  • @jcarpio5410
    @jcarpio5410 Рік тому +1

    can I add more than one floating text?

    • @jonbednez
      @jonbednez  Рік тому

      yep! you could modify each components' offset to help with overlap. what are you looking to do?

    • @jcarpio5410
      @jcarpio5410 Рік тому

      Can this work on Augmented Reality? Because what I want to do is to augment the 3d object with floating text above it or all round it.

    • @jonbednez
      @jonbednez  Рік тому +1

      @@jcarpio5410 Great question. TBH, I have never worked with Augmented Reality, so I can't speak to that. However, if you are using a World Space Canvas and a Camera in your scene, it would lead me to believe it would be possible. (but I haven't tested with AR). I found this tutorial -> ua-cam.com/video/HyQBv_1nhxQ/v-deo.html. It says using 3d world space UI with AR. I hope this helps! Thank you for your question. (If this works with AR, please let me know! I am very curious)

    • @jcarpio5410
      @jcarpio5410 Рік тому +1

      @@jonbednez I really appreciate the reply and help. Thank you so much 🙌

    • @jonbednez
      @jonbednez  Рік тому +1

      @@jcarpio5410No problem! If you have any other Unity and/or game related questions please let me know. I hope your project goes well. Have a good one.

  • @nortal6006
    @nortal6006 Рік тому

    i have a problem where it won't show the text in game but in scene it does

    • @jonbednez
      @jonbednez  Рік тому

      hey! is the world space canvas too large? has that canvas been adjusted to be in front of the camera? maybe the scale of the ui? could be font size is too large?

  • @johngrey5806
    @johngrey5806 3 місяці тому

    You're obscuring the Inspector with your weirdly skewed webcam. Do we really need to see you? Can't see what you're clicking on in there. If we really must see your face, could you put it on the other side of the screen where you're not obscuring important info?

    • @jonbednez
      @jonbednez  3 місяці тому

      hey! sorry about that. In the future I will def be mindful of the webcam. That’s a good idea about moving to the left of the screen. No, my face doesn’t have to show. I’m trying to learn what works and doesn’t with video. Thanks for the feedback.

    • @johngrey5806
      @johngrey5806 3 місяці тому

      @@jonbednez alright then, I pardon you. Now iron your hands for repentance and you shall be absolved. Thanks for your tutorial.

    • @jonbednez
      @jonbednez  3 місяці тому

      @@johngrey5806lol. np.