目前,我遇到了一个问题,就是我正在将数字输出到GUIText中,并且由于某种原因,当数字发生变化时,它会将新的数字写在旧的数字之上,而不是改变数字。
我不知道为什么会发生这种情况,因为我只编写了一个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);
}}
发布于 2014-09-22 11:12:51
我现在已经对它进行了排序,结果是,当我加载脚本在twice...hehe oops中的级别时,我才调用该脚本。:)
https://stackoverflow.com/questions/25929998
复制相似问题