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

如何修复Unity中C#脚本的CS1003 ',' expected语法错误

解决Unity中CS1003编译错误(缺少',')

你的CS1003错误是因为代码第8行的变量声明缺少类型定义。C#语法要求定义公开字段时必须明确指定变量类型,原代码中FlightForce没有声明类型,导致编译器解析失败。

修正后的完整代码:

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

public class PlayerMovement : MonoBehaviour
{
    public Rigidbody2D rb;
    public Vector2 FlightForce = new Vector2(0f, 10f); // 补充Vector2类型声明

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            rb.AddForce(FlightForce, ForceMode2D.Force);
        }
    }
}

内容的提问来源于stack exchange,提问作者Tihudzy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 06:54:06