我正在尝试创建一个描述运行时对象的文本,GUIText对象已创建,但它不可见。有什么想法吗?
下面是我的代码:
void enemydescriptionInit( GameObject text, string desc){
text.transform.parent = enemyCar1.car.transform;
enemyCar1.car.transform.position = enemyCar1.startPosiotion;
text.gameObject.GetComponent<GUIText> ().font = new Font ("Arial");
text.gameObject.GetComponent<GUIText>().text = desc;
text.gameObject.GetComponent<GUIText>().fontSize = 40;
text.gameObject.GetComponent<GUIText>().fontStyle = FontStyle.BoldAndItalic;
text.gameObject.GetComponent<GUIText>().color = Color.blue;
text.gameObject.name = "Desc";
}
void Start () {
player = GameObject.Find ("Player");
text = new GameObject();
text.AddComponent<GUIText>();
}
void Update(){
enemydescriptionInit (text, "HELLO");
}发布于 2015-07-02 19:50:49
如果您正在使用Unity5,请尝试使用UnityEngine.UI
只需使用Text而不是GUIText
希望能有所帮助
发布于 2015-08-31 00:53:28
尝试使用OnGUI()方法
此示例代码
void OnGUI(){
GUIStyle style = new GUIStyle();
style.fontSize = 30;
style.alignment = TextAnchor.UpperRight;
GUI.Label (new Rect(Screen.width/2 , 10 , 100 ,40) , "Time left " + secondsLeft.ToString() , style);
}https://stackoverflow.com/questions/30635066
复制相似问题