[英]Unity GUIText writing on top of itself C#
我目前在統一方面遇到問題,我正在將數字輸出到GUIText中,並且由於某種原因,當數字更改時,它會將新數字寫在舊數字的頂部,而不是更改數字。
我不知道為什么會這樣,因為我只有1個正在寫入的GUIText,正在執行寫入操作的腳本僅在一個對象上,而我正在更改當前正在寫入GUItext的變量,而不是將其切換為一個新的。
任何幫助,將不勝感激,謝謝。
代碼被稱為 :
公共類RNG:MonoBehaviour {
public GUIText thisAnswer;
public RaycastHit hit = new RaycastHit ();
public Camera mycam;
int randomNumber = 0;
int miniScore = 0;
int CorrectCount = 0;
int refreshCount = 0;
// Use this for initialization
void Awake ()
{
}
void Start ()
{
}
void FixedUpdate ()
{
refreshCount += 1;
}
// Update is called once per frame
void Update ()
{
if (CorrectCount != 5) {
StartCoroutine (Selection ());
thisAnswer.text = "" + randomNumber;
if (refreshCount % 200 == 0) {
Refresh ();
}
} else {
PlayerPrefs.SetInt ("MiniScore", miniScore);
Destroy (GameObject.Find ("Killswitch"));
}
}
IEnumerator Selection ()
{
if (Camera.main != null) {
Ray ray = mycam.ScreenPointToRay (Input.mousePosition);
if (Input.GetKeyUp (KeyCode.Mouse0)) {
if (Physics.Raycast (ray, out hit)) {
if (hit.transform.tag == "answer") {
if (System.Convert.ToInt32 (thisAnswer.text) % 3 == 0) {
miniScore = miniScore + 100;
CorrectCount = CorrectCount + 1;
randomNumber = Random.Range (0, 36);
yield return new WaitForEndOfFrame ();
} else if (System.Convert.ToInt32 (thisAnswer.text) % 3 != 0) {
if (miniScore > 50) {
miniScore = miniScore - 50;
} else if (miniScore < 50) {
miniScore = 0;
}
randomNumber = Random.Range (0, 36);
yield return new WaitForEndOfFrame ();
}
}
}
}
}
}
void Refresh ()
{
randomNumber = Random.Range (0, 36);
}
}
我現在對它進行了排序,結果發現我只是在兩次加載腳本的級別后才調用腳本...哎呀,糟糕。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.