首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >统一的GUIText写在自己的上面,C#

统一的GUIText写在自己的上面,C#
EN

Stack Overflow用户
提问于 2014-09-19 08:53:20
回答 1查看 347关注 0票数 0

目前,我遇到了一个问题,就是我正在将数字输出到GUIText中,并且由于某种原因,当数字发生变化时,它会将新的数字写在旧的数字之上,而不是改变数字。

我不知道为什么会发生这种情况,因为我只编写了一个GUIText,正在编写的脚本只在一个对象上,并且我正在更改当前写入GUItext的变量,而不是将它切换为一个新的对象。

如能在这方面提供任何帮助,将不胜感激。

代码被称为

公共类RNG : MonoBehaviour {

代码语言:javascript
复制
    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);


    }

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-22 11:12:51

我现在已经对它进行了排序,结果是,当我加载脚本在twice...hehe oops中的级别时,我才调用该脚本。:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25929998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档