Unity 3D : Menus Part 2 (Text-Mesh-PRO in 5 Minutes!!)

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

ความคิดเห็น • 49

  • @TheRoyalSkies
    @TheRoyalSkies  3 ปีที่แล้ว +10

    For anyone wondering what the website was for all the fonts here it is:
    www.dafont.com/theme.php?cat=303&page=3
    Code for the tutorial can be found below!
    {
    public TMPro.TextMeshProUGUI myText;
    public int myScore;
    public RectTransform myRect;
    void Update()
    {
    myText.text = "Your score is: " + myScore;
    myText.fontStyle = TMPro.FontStyles.Bold;
    myText.color = new Color(1, 0, 0, 1);
    myRect.transform.localPosition = new Vector3(30, 80, 0);
    myRect.localScale = new Vector3(1, .5f, 1);
    myRect.sizeDelta = new Vector2(360, 600);
    }
    }

    • @Build_the_Future
      @Build_the_Future 3 ปีที่แล้ว +3

      hope you keep going with Unity tutorials I'm really enjoying them. I hope you can cover, Animations, Ik, explain how and why to use quaternion, Animation stats, Animation controllers/avatars, blending, physics, How to speed up FPS, Useful assets on the store, Unity apps, etc.

    • @TheRoyalSkies
      @TheRoyalSkies  3 ปีที่แล้ว +1

      @@Build_the_Future So glad to hear you're enjoying the content - You'll be happy to hear that the vast majority of those will be covered in the "Advanced Unity Animation Programming Series". It's probably gonna be in a month or two :)

    • @TonyAnima_Projects
      @TonyAnima_Projects 3 ปีที่แล้ว

      Nice tutorial of menus in Unity3D. Now just a small question. I've been trying based on some FPS tutorials and I had the idea of making the color for the magazine / clip to change from white to red when it is less than 3 and to gray when it is zero. However, after I coded to the UIController script of my mini-game, it didn't loaded properly.
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class UIController : MonoBehaviour
      {
      public Font fontHUD;
      public PlayerBehaviour player;
      public static UIController instance;
      public AimUIBehaviour aimUI;
      // Start is called before the first frame update
      void Start()
      {
      instance = this;
      }
      // Update is called once per frame
      void Update()
      {
      }
      void OnGUI()
      {
      GUI.skin.font = fontHUD;
      GUI.contentColor = Color.white;
      GUI.Label(new Rect (Screen.width - 100, Screen.height - 85, 200, 80), player.weapons[0].currentAmountAmmo+" / "+player.weapons[0].currentAmountAmmoTotal);
      if (player.weapons[0].currentAmountAmmo > 3)
      {
      GUI.contentColor = Color.red;
      }
      }
      }
      Originally the currentAmountAmmo and currentAmountAmmoTotal were private classes and were picking up the information from ammoUsed and ammoTotal (public classes), but I had to change them to public while I was trying to test it. And I know I should share the other scripts in case you want to have some basic idea from what I was working on, but I'm still working at some intervals, which from one moment to another the scripts might be modified.
      In the future, do you plan to make a tutorial in how to code the text to change from one color to another by some conditions in Unity3D - like from white or other color when - for example: 30/30, yellow when 15/30, red when 3/30 and gray when 0/30? That will help for sure.

    • @IchigoFurryModder
      @IchigoFurryModder 3 ปีที่แล้ว +1

      @@TonyAnima_Projects First of all, that's not quite how you do singletons, you need to check that instance is null before doing anthing, and it's good practice to do that stuff in Awake, like so:
      void Awake()
      {
      if (instance == null)
      instance = this;
      else
      Destroy(gameObject);
      //DontDestroyOnLoad(gameObject); // You usually do this with singleton components, like with an AppManager or GameManager class, but in your specific case I don't suppose you want that.
      }
      I'm guesing your problem is the label stays white? I'm pretty sure you're supposed to change the content color *before* rendering your element, try it like so:
      if (currNumber > 3) GUI.contentColor = Color.white;
      else if (currNumber == 0) GUI.contentColor = Color.grey;
      else GUI.contentColor = Color.red;
      GUI.Label(new Rect (Screen.width - 100, Screen.height - 85, 200, 80), $"{currNumber} / {maxNumber}");
      But consider using the UI system.

    • @TonyAnima_Projects
      @TonyAnima_Projects 3 ปีที่แล้ว

      @@IchigoFurryModder Thanks for the tips and indications, Ichigo. That will surely help. :D

  • @nocturne6320
    @nocturne6320 3 ปีที่แล้ว +15

    A few tips for optimisation. If you're going to change the text often (like a score display) don't enable the font auto size, instead just set the size manually. If you don't actually need the extra effects like outline or shadow, leave them unchecked in the material settings.
    Also as others mentioned, use String.format, or the $ sign with {} in strings instead of + and just use "using TMPro;" at the top of your code.
    Or if you're working with a lot of text you want to concatenate each frame, use the StringBuilder class and store it in a variable at the top of your script, don't just do "new StringBuilder" each time in the update method.

  • @issacthompson330
    @issacthompson330 3 ปีที่แล้ว +8

    The best part of TMPro is how much you can do with it with ease. TMP has a variable in its Info that tells how many characters of the text are visible so you can use an update function or a corutine to make it fill in the text as fast as you want.

  • @gnosisdarkmatter
    @gnosisdarkmatter 3 ปีที่แล้ว +8

    I got distracted after I read this. 3:28
    "This is a paragraph. It's like, the best paragraph ever -"
    "This is the second paragraph. It's like, the second best paragraph ever -"
    "This is the last paragraph. It's totally the worst paragraph ever -"

  • @ArkTheDuckh
    @ArkTheDuckh 3 ปีที่แล้ว +11

    Oh nice. Congrats on 100K btw

  • @MikeKing710
    @MikeKing710 3 ปีที่แล้ว +1

    Best exploration of what we have in Text Mesh!

  • @paulorodriguez6288
    @paulorodriguez6288 3 ปีที่แล้ว +1

    yes this is the quick info a beginner like me needs. thankyou

  • @Antonybae
    @Antonybae 3 ปีที่แล้ว +5

    Nice tutorial!
    "Your score is: " + myScore
    uses concatenation which creates 3 new string variables in memory.
    for strings its better to write:
    $"Your score is: {myScore}"
    which uses interpolation and creates only one string variable).
    Its not a big optimization but using '+' operator is kinda bad practice(especially in enterprise)

    • @TheRoyalSkies
      @TheRoyalSkies  3 ปีที่แล้ว +2

      My mind is Blown - Thank you for sharing this, I didn't know that was a thing, I will definitely try and get into the habit of using this instead!

  • @WeeGification
    @WeeGification 3 ปีที่แล้ว +1

    You mad lad, I've been avoiding TMPro because of not being able to use any Fonts, that font object conversion changed my life.
    I'd followed you for blender tips but I've been using unity for 2+ years so when you switched to intro unity tutorials I wasn't sure I get anything out of it, but here I am getting taken to school. Good stuff!

    • @TheRoyalSkies
      @TheRoyalSkies  3 ปีที่แล้ว

      No problem man - I'm glad you got something new out of it, and thank you for sticking around for so long. If you've been here since Blender, you're probably a Legacy sub lol. It's good to see you guys in these vids :)

    • @WeeGification
      @WeeGification 3 ปีที่แล้ว +1

      @@TheRoyalSkies Yeah man, some of the best tutorials on youtube, some of the only that don't waste your time. I heard you're gonna be making more advanced unity stuff soon, looking forward to it. Keep doing what you're doing man

  • @CleisonRodriguesComposer
    @CleisonRodriguesComposer 3 ปีที่แล้ว +1

    The best tutorial about Text-Mesh-Pro!
    Thank you!

  • @MarkChong
    @MarkChong 3 ปีที่แล้ว

    This guy will save your time and NEVER WASTE IT

  • @noirlavender6409
    @noirlavender6409 3 ปีที่แล้ว +2

    Thank you man. Once I get out of poverty because of your wisdom and awesome tutorials I'll put your name and links on the credits

  • @TheKnightDark
    @TheKnightDark 3 ปีที่แล้ว +1

    As always great tutorial. Thanks!

  • @pixspaces4777
    @pixspaces4777 3 ปีที่แล้ว +1

    Really helpful, I knew about using TMP for static text but using it for score system always gave me errors and bugs, thanks a lot for simplifying it! Also congratulations on 100k+sub!

  • @mynameisearlb
    @mynameisearlb 15 วันที่ผ่านมา

    I just learned about TMPro and this was the video i needed, thanks!

  • @vellyxenya3970
    @vellyxenya3970 3 ปีที่แล้ว

    Congrats on 100K!!!

  • @CreativeSteve69
    @CreativeSteve69 3 ปีที่แล้ว

    I love coming back here for help as I"m making my first simplistic game. :D

  • @UnderfundedScientist
    @UnderfundedScientist 3 ปีที่แล้ว +2

    keep up the great work

  • @flicker_117
    @flicker_117 3 ปีที่แล้ว +4

    AYYY...100K

  • @kriegs8315
    @kriegs8315 3 ปีที่แล้ว +1

    yes

  • @animatrix1490
    @animatrix1490 3 ปีที่แล้ว

    Thank you so much for making these

  • @Thesupperals
    @Thesupperals 3 ปีที่แล้ว +3

    Yo. Don't forget to tell the script that you're using Unity's TMP library. This will help you access a all of things that TextMeshPro offers that you otherwise wouldn't be able to access.

    • @IchigoFurryModder
      @IchigoFurryModder 3 ปีที่แล้ว +1

      And if you're using assembly definition files *as you probably should* don't forget you need to reference TMP in there

  • @ColdOneK
    @ColdOneK 3 ปีที่แล้ว

    For using Text Mesh Pro w/ script, you can add using TMPro;
    For creating font assets, I tend to add a bunch at a time, so I go Window/TextMeshPro/FontAssetCreator -- add your font - generate font atlas - then save -- you can then drag the created file to where you keep your fonts, so if you want to use that font in another project, you can simply drag both the font + the font atlas file into the new project.

    • @FlappyBandAid
      @FlappyBandAid 3 ปีที่แล้ว

      Man THANK YOU! Worked like a charm!

  • @Hyphen3372
    @Hyphen3372 3 ปีที่แล้ว

    thanks

  • @Caden_Burleson
    @Caden_Burleson ปีที่แล้ว

    @3:35 Same 😂

  • @CrimsonGamer23
    @CrimsonGamer23 3 ปีที่แล้ว

    Let’s say I’ve designed some number for score and I have them set up individually as a png. Can I use the png or set them up as fonts?

    • @TheRoyalSkies
      @TheRoyalSkies  3 ปีที่แล้ว +1

      You can use the png if you want. If you have a png for each number you could have an array of each png, and set them to appear based on the number for the score -

    • @CrimsonGamer23
      @CrimsonGamer23 3 ปีที่แล้ว

      @@TheRoyalSkies Thanks!

  • @officialsquadrilogystudio
    @officialsquadrilogystudio 3 ปีที่แล้ว

    Game coding reminds me a lot of algebra class

  • @kittentacticalwarfare1140
    @kittentacticalwarfare1140 3 ปีที่แล้ว +1

    The Aliens are *AMOGUS*

  • @PlanetXtreme
    @PlanetXtreme 3 ปีที่แล้ว +1

    ur funi

  • @technofeeliak
    @technofeeliak 3 ปีที่แล้ว +1

    You had 69 likes. Sorry to ruin your fun but I added one.

    • @TheRoyalSkies
      @TheRoyalSkies  3 ปีที่แล้ว

      I legit almost chocked on my coffee reading this comment - Haha, It's OK to ruin my fun if it's for the good of the channel -!