繁体   English   中英

Unity:错误 CS1519:class、结构或接口成员声明中的标记“=”无效,

[英]Unity: error CS1519: Invalid token '=' in class, struct, or interface member declaration,

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

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;

    }

}

您需要为变量定义一个类型。

transform.position 是 Vector3 类型。

尝试这个:

Vector3 偏移量 = transform.position;

您应该删除Vector3 offset = transform.position; 并添加offset = transform.position; Start()Awake()下,查看下面的链接了解更多信息。 C# 不允许除常量、构造函数和 static 字段之外的字段初始值设定项。 transform.position是一个非静态字段。

为什么我不能将 transform.position 分配给 Vector3 object?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM