Search Unity

Text system in unity 2d

Discussion in 'Scripting' started by kilicefekun, Jan 6, 2021.

  1. kilicefekun

    kilicefekun

    Joined:
    Nov 22, 2020
    Posts:
    8
    the title was incorrect but I can't edit it for some reason.
    I am making a topdown game for my classmates and I want to be able to talk to the NPCs,
    So I wanna do these things,
    1 - an "!" pops up NPCs's head when you get near
    2 - you can press a button to show and hide the textbox when you are near.
    that's it.
    so how do I do it? (pls help I am a noob)
     
  2. kilicefekun

    kilicefekun

    Joined:
    Nov 22, 2020
    Posts:
    8
    and btw you can make it so the text appears when you go near the npc, that'll work too
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Break your problem down into small pieces...

    • Figure out how to display text in the game world.
    • Figure out how to position that text at a particular place
    • Figure out how to print to the console when the player gets near an NPC
    • Figure out how to print to the console when the player presses a button
    • Figure out how to give an NPC a list of dialogue to say
    • Combine all of the above
     
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    Definitely start with any of the Unity "Learn" tutorials series, or look around on Youtube, such as Brackeys on Youtube.

    As @PraetorBlue points out above, you have to first understand the problem before you can consider how to solve it, and tutorials can begin to show you how Unity and its environments work.
     
  5. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    Use a circle collider 2D on your player that's as big as the distance you want from the NPCs (so when it collides, the text is shown). This is in addition to the player's collider.
    The text boxes should be attached to the NPCs, and you can show/hide them (and change their text) as needed.
    As mentioned, there's a lot of steps for you to figure out, but it's all pretty straightforward. Just do things one at a time.
     
    PraetorBlue likes this.
  6. kilicefekun

    kilicefekun

    Joined:
    Nov 22, 2020
    Posts:
    8
    thanks, I'll try that