title: Unity C# , get text width / font character width
body: <p>I want to get the width of a text in unity using C# .</p>
  
  <p>Here is what I am trying to do . </p>
  
  <pre><code>int GetWidthOfMessage(string message)
  {
      int totalLength = 0;
  
      Font font = text.font; //text is my UI text
      CharacterInfo characterInfo = new CharacterInfo();
  
      char[] arr = message.ToCharArray();
  
      foreach (char c in arr)
      {
          font.GetCharacterInfo(c, out characterInfo, text.fontSize);
          totalLength += characterInfo.advance;
      }
  
      return totalLength;
  }
  </code></pre>
  
  <p>But font.GetCharacterInfo(...) returns false and characterInfo.advance is 0 for any character . </p>