Unity:错误CS1519:类,结构或接口成员声明中的无效令牌'=',

问题描述 投票:-1回答:2

我是编码的新手,从我的收集中,以下代码被编写为与C#4.0兼容,而不与当前版本兼容。标题中还有另一个我无法容纳的错误:令牌无效 ';'在类,结构或接口成员声明中]

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

public class camera_controller : MonoBehaviour
{

    public GameObject player;
    private Vector3 offset;
    Vector3 offset = transform.position;


    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    void LateUpdate () 
    {

    transform.position=player.transform.position+offset;

    }

}

我是编码的新手,从我的收集中,以下代码被编写为与C#4.0兼容,而不与当前版本兼容。标题中还有另一个我不适合的错误:...

c# unity3d syntax-error
2个回答
0
投票

您需要定义变量的类型。


0
投票

您应删除Vector3 offset = transform.position;并在offset = transform.position;Start()下添加Awake(),有关更多信息,请参见下面的链接。除了常量,构造函数和静态字段外,C#不允许字段初始化程序。 transform.position;是非静态字段。

© www.soinside.com 2019 - 2024. All rights reserved.