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
相关产品推荐
相关产品推荐

