在游戏开发中经常用到一些数字,例如在游戏中的倒计时、得分等。这些数字用系统字体很好实现在unity中如何实现。
using UnityEngine;using System.Collections;public class GUIShow : MonoBehaviour { public string myStringScore; public float x = 85; public float y = 19; public float scale = 1; public Color myColor; //定义数组 public Texture[] myNumber = new Texture[10]; private int index = 0; private int width = 30; private int height = 72; void OnGUI() { GUI.color = myColor; if (myStringScore != null) { for (int i = 0; i < myStringScore.Length; i++) { GUI.DrawTexture(new Rect(x + i * scale * width, y, scale * width, scale * height), myNumber[int.Parse(myStringScore.Substring(i, 1))], ScaleMode.StretchToFill, true, 0); //GUI.DrawTexture(new Rect(x + i * scale * width, y, scale * width, scale * height),myNumber[myStringScore[i]-48]); } } }用数组的方式来获取每一个位置的数字再用DrawTexture函数打印到界面上。你可以改变myStringScore的数值,输出的结果就不同。