【问题标题】:scoreText.text not working in unityscoreText.text 不能统一工作
【发布时间】:2017-10-16 11:16:33
【问题描述】:

“分数:”未在统一 ide 上显示。我尝试了很多,但似乎没有任何效果,也没有按预期获得输出。谢谢。抱歉英语不好。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class uiManager : MonoBehaviour {
public Text scoreText;
int score;

// Use this for initialization
void Start () {
    score = 0;

}
void score_view()
{
    score = move.score;
    Debug.Log("uiManager Score:"+score);
    scoreText.text = "Score:"+score;
}

// Update is called once per frame
void Update ()
{
    score_view();

}
}

【问题讨论】:

  • Update 仅在游戏运行时运行。如果您不运行游戏,您将看不到这一点

标签: c# unity5


【解决方案1】:

如果您的游戏对象处于活动状态并且您的脚本已启用,则每帧调用一次更新。
此外,您的游戏应该正在运行。

https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html

您可以使用以下变量检查此状态:

this.gameObject.activeSelf
this.enabled

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 2012-10-04
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多