C#错误CS0029

时间:2018-07-30 18:37:06

标签: c# unity3d unityscript

我一直在控制台中收到此错误:资产/脚本/ScoreScript.cs(37,25):错误CS0029:无法将类型'int'隐式转换为UnityEngine.UI.Text

这是我的代码:

public class ScoreScript : MonoBehaviour
{
    public static int score = 0;
    public Text scoreText;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Score")
        {
            scoreText.text = (++score).ToString();
            Destroy(collision.gameObject);
            return;
        }
        else if (collision.tag == "Obstacle")
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            scoreText = 0;
        }
    }
}

1 个答案:

答案 0 :(得分:3)

在此处更改此行:

scoreText = 0;

收件人:

scoreText.text = 0.ToString();