Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active February 13, 2019 03:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tsubaki/a7be4ce3240bc8869503706bc711d879 to your computer and use it in GitHub Desktop.
Save tsubaki/a7be4ce3240bc8869503706bc711d879 to your computer and use it in GitHub Desktop.
TextMeshProにて、GC無しで数字を表現する(ビルド後のみ・5桁まで)
using UnityEngine;
using TMPro;
public class ShowCharacter : MonoBehaviour
{
[SerializeField]
TextMeshProUGUI label;
[Range(0, 99999)]
[SerializeField]
int count;
int[] characters = new int[5];
void Update()
{
var value = count;
for(int i= characters.Length - 1; i>=0 ; i--)
{
characters[i] = (value % 10) + 48;
value /= 10;
}
label.SetCharArray(characters, 0, characters.Length);
}
}
@tsubaki
Copy link
Author

tsubaki commented Feb 3, 2019

46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment