Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Textmesh.text from an ascii code?

Discussion in 'Scripting' started by Alvarus, May 22, 2009.

  1. Alvarus

    Alvarus

    Joined:
    Apr 10, 2009
    Posts:
    203
    I'm trying to update a textmesh procedurally using an ascii code, but I'm having a heck of a time. I've tried seting the textmesh equal to the ascii code, I've tried this too:

    var c=Convert.ToInt32(59);
    tempstr = Convert.ToChar(c);
    and then tried setting the textmesh to tempstr...

    and it complains that I can't convert char to a string.

    This seems to be a relatively simple thing to do...in basic it's just chr$(59)...a little help?
     
  2. Alvarus

    Alvarus

    Joined:
    Apr 10, 2009
    Posts:
    203
    Fixed by my brother using a c# script:

    Code (csharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4.  
    5. public class CharConverter : MonoBehaviour {
    6.  
    7.    
    8.     String convertit(int a){
    9.     byte[] myByteArray = System.Text.Encoding.ASCII.GetBytes("a");
    10.     myByteArray[0] = (byte)a;
    11.     return System.Text.Encoding.ASCII.GetString(myByteArray );
    12. }
    13.  
    14. }
    15.  
    call it with convertit(ASCII)
     
  3. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Keep it simple:

    Code (csharp):
    1.  
    2. var s:String = "";
    3. s += System.Convert.ToChar(110);
    4.