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

Question How do I make console appear in-game?

Discussion in 'Scripting' started by Arizen1451yt, Jul 3, 2023.

  1. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    5
    My game's points system shows the points in the console, and I was wondering how to make these appear on the screen briefly before disappearing, like damage values in most games.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Debug.Log and the developer console are just that - for development and debugging.

    If you want to show text on screen in your game you should use UI text elements like TextMeshProUGUI or the legacy Text component, or game world 3D text elements such as TextMeshPro.
     
  3. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    5
    I know they are for debugging, but is it possible to show the text from it in-game, or only in editor?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    You're thinking about it the wrong way. Don't try to show the Debug logs in the game. Just make a function in your game to show text and call that instead of Debug.Log.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Tons of tutorials for this but if you like, here's an ultra-low-tech one that I pulled out of my Kurt Arcade game.

    It uses the old built-in TextMesh but you could upgrade it to the new TextMeshPro if you like.

    If the font is borked / pink, just re-drag your desired font into the TWO places on the Prefab's children.

    Screenshot-arcade-133328182017862940.png

    Appstore: https://apps.apple.com/ch/app/kurt-arcade/id1591748111
    Google Play: https://play.google.com/store/apps/details?id=com.kurt.arcadetv
     

    Attached Files:

  6. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    546
    Code (CSharp):
    1. // Instantiates some text and then destroys it after a few seconds
    2.     void CreateText(string text,Vector3 position, Quaternion rotation)
    3.     {
    4.         GameObject obj=new GameObject("Text");
    5.         obj.transform.position=position;
    6.         obj.transform.rotation=rotation;
    7.         TextMesh myText=obj.AddComponent<TextMesh>();
    8.         myText.text=text;
    9.         myText.characterSize=0.1f;
    10.         myText.fontSize=64;
    11.         StartCoroutine(DestroyText(obj));
    12.     }
    13.  
    14.     IEnumerator DestroyText(GameObject obj)
    15.     {
    16.         yield return new WaitForSeconds(3);
    17. // fade the text away
    18.         MeshRenderer m=obj.GetComponent<MeshRenderer>();
    19.         Color c=m.material.color;
    20.         while (c.a>0.01f)
    21.         {
    22.             c.a-=0.01f;
    23.             m.material.color=c;
    24.             obj.transform.position+=Vector3.up*0.02f;
    25.             yield return null;
    26.         }
    27.         Destroy(obj);
    28.     }
     
  7. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    5
    I get it now. Thank you, these 2 messages helped a lot.