You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity项目Score.cs脚本出现CS1519错误,请求技术支持

Unity Score.cs脚本编译错误排查与解决

错误原因

你遇到的Assets\Score.cs(10,16): error CS1519: Invalid token ';' in class, record, struct, or interface member declaration编译错误,实际是代码中属性名大小写误用导致的:Unity UI的Text组件用于设置显示文本的属性是小写的text,而非大写的Text,这个错误让编译器无法正确识别语法,进而抛出无效令牌的提示。

解决方法

将Update方法内的scoreText.Text修改为scoreText.text即可,具体修正后的完整代码如下:

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

public class Score : MonoBehaviour
{
    
    public Transform player;
    public Text scoreText;

    // Update is called once per frame
    void Update()
    {
        scoreText.text = player.position.z.ToString("0");
    }
}

修改完成后保存脚本,Unity会自动重新编译项目,错误即可消除。

内容的提问来源于stack exchange,提问作者SƠN QUÂN PHẠM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 11:47:34