什么是“类中的无效令牌”错误?

问题描述

我一直在使用我正在制作的游戏的教程指南来弄清楚基础知识,在编写碰撞代码时遇到了两个错误:

  1. 声明的类,结构或接口成员中的无效令牌“ {”和
  2. 类型或名称空间定义,或预期的文件结尾。

代码如下:

using UnityEngine;

public class PlayerCollision : MonoBehaviour
{
 public PlayerMovement movement;
 {
  void OnCollisionEnter (Collision collisonInfo)
  {
   if (collisonInfo.collider.tag == "Obstacles")
    movement.enabled = false;
  }
 }
}

解决方法

您好像花括号过多:

public class PlayerCollision : MonoBehaviour
{
    public PlayerMovement movement;
    void OnCollisionEnter(Collision collisonInfo)
    {
        if (collisonInfo.collider.tag == "Obstacles")
            movement.enabled = false;
    }
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...