Search Unity

3D Text

Discussion in 'Editor & General Support' started by Jorgen, Jun 2, 2006.

  1. Jorgen

    Jorgen

    Joined:
    Dec 13, 2005
    Posts:
    38
    3D Text, available since v 1.5 beta 2 (?), seems to be rendered in front of the other elements in the scene. Is this intended?
     
  2. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    The default text uses GUI->Text Shader, which always renders in front of everything else. Create a new font material and give it a different shader to fix this.

    For what it's worth, it's always been possible to make 3D text, providing you assemble the object manually. Check out Component->Mesh->Text Mesh on the menu.
     
  3. rke

    rke

    Joined:
    Mar 17, 2006
    Posts:
    2
    I just played with Text Mesh and got it nicely showing my text and setting it from a script. But then I wanted to assign a collider to it (ultimately to try to create something like a selection). I cant get a raycast to hit the text mesh...
    Do I need to assign a mesh to the collider? and How do I do that with a Text Mesh?
     
  4. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    I don't think you can. I bet the best way would be to caculate how wide the string is and that make a box collider that fits to that size every frame. Hard, but possible.
     
  5. Jorgen

    Jorgen

    Joined:
    Dec 13, 2005
    Posts:
    38
    Thanks for your reply, Neil.
    If I do as you propose, I get a black font (given that I use a alpha shader) that can not be seen from the back, and I can not change its color to anything but black.

    Ideas?
     
  6. Jorgen

    Jorgen

    Joined:
    Dec 13, 2005
    Posts:
    38
    I figured it out!

    Based on a shader sample from the UnifyWiki, I hacked together a new shader that enables Text Meshes to have
    - Colors
    - Backfaces
    - Alpha
    - Z-sorting

    Code (csharp):
    1.  
    2. Shader "ShiftControl/Colored 3DText Shader" {
    3.    
    4.     Properties {
    5.         _Color ("Main Color", Color) = (1,1,1,1)
    6.         _MainTex ("Font Texture", 2D) = "white" {}
    7.     }
    8.    
    9.     SubShader {
    10.         Lighting Off
    11.         cull off
    12.         ztest never
    13.         Zwrite off
    14.         Fog { Mode Off }
    15.         Tags {"Queue" = "Transparent" }
    16.        
    17.         Pass {
    18.             Blend SrcAlpha OneMinusSrcAlpha
    19.             SetTexture [_MainTex] {
    20.                 constantColor [_Color]
    21.                 Combine constant * constant, texture
    22.             }
    23.         }
    24.     }
    25. }
    26.  
    As this is my first shader, ever, I guess it has room for some improvement. Anyone?
     
  7. BLSCLACobra

    BLSCLACobra

    Joined:
    Feb 3, 2010
    Posts:
    17
    this is kinda dead but there isn't a lot of info on 3DText...

    but can anyone pls explain me a bit on how to switch fonts with 3DText?

    Code (csharp):
    1. IEnumerator ChangeFont()
    2.     {
    3.         int i= fontRange;
    4.         while(true)
    5.         {
    6.             yield return new WaitForSeconds(0.3f);
    7.             Debug.Log(i);
    8.             style.font = fonts[i];
    9.             bartext.font = style.font;
    10.             bartext.material = fontMaterial[i];
    11. //          bartext.text = btext;
    12.             text3D.font = style.font;
    13.             text3D.renderer.material = fontMaterial[i];
    14.             text3D.text = btext;
    15.            
    16.             i++;
    17.             if(i == fontRange+2)
    18.             {
    19.                 i = fontRange;
    20.             }
    21.         }
    22.     }
    23.  
    this loops true the fonts and as you can see sets the Font and the Material.
    it works with GUI Text but doesn't seem to work with 3D Text.

    does anyone know why??