我一直在控制台中收到此错误:资产/脚本/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;
}
}
}
答案 0 :(得分:3)
在此处更改此行:
scoreText = 0;
收件人:
scoreText.text = 0.ToString();