简体   繁体   English

Unity 显示“错误 CS1022:类型或命名空间定义,或预期的文件结尾”

[英]Unity says "error CS1022: Type or namespace definition, or end-of-file expected"

I am making a cross board game using Unity based on a tutorial.我正在根据教程使用 Unity 制作跨棋盘游戏。 This problem occurs when I add a jump animation.当我添加跳跃动画时会出现此问题。 All my code is from that tutorial and no changes have been made except for one value.我所有的代码都来自该教程,除了一个值外没有做任何更改。

I know which line of code is wrong but I don't know why and I don't know how to fix it.我知道哪一行代码是错误的,但我不知道为什么,也不知道如何修复它。

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

public class Playermovement : MonoBehaviour
{
  private Rigidbody2D rb;
    public float jumpAmount = 1;

    bool isGrounded;
    public Transform groundCheck;
    public LayerMask groundlayer;
    public Animator anim;
    public float overlap = 0.5f;
   

    void Start()
    {

        rb = gameObject.GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (isGrounded)
            {
                Jump();
            }
        }
    }

    private void FixedUpdate()
    {
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, overlap, groundlayer);
    }

    void Jump()
    {
        rb.AddForce(Vector2.up *5* jumpAmount, ForceMode2D.Impulse);
    }

    if(isGrounded)
        {
            anim.SetBool("Jump",false);
        }
        else
        {
            anim.SetBool("Jump", true);
        }
}

Does anyone know what's wrong with this, please?请问有人知道这是怎么回事吗? Thank you in advance to those who answered!先谢谢回答的人了!

Assets\Script\Playermovement.cs(52,1): error CS1022: Type or namespace definition, or end-of-file expected Assets\Script\Playermovement.cs(52,1):错误 CS1022:类型或命名空间定义,或预期的文件结尾

This is the error message I received.这是我收到的错误消息。 I know it tells me the error occurred on the first character of line 52 (which is the last line), but other than that I don't know anything because there is only one curly bracket on that line.我知道它告诉我错误发生在第 52 行(最后一行)的第一个字符上,但除此之外我什么都不知道,因为该行只有一个大括号。

The problem is with if (isGrounded) statement.问题在于if (isGrounded)语句。 The if/else statement needs to be in a method/function , and can't work without being in one. if/else语句需要在method/function中,如果不在其中就无法工作。

暂无
暂无

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

相关问题 错误 CS1022:类型或命名空间定义,或文件结尾预期的统一 3d 游戏引擎 - error CS1022: Type or namespace definition, or end-of-file expected unity 3d game engine 错误CS1022:类型或名称空间定义,或预期的文件结尾 - error CS1022: Type or namespace definition, or end-of-file expected 我遇到消息错误 CS1022: Type or namespace definition, or end-of-file expected - I'm having a problem with the message error CS1022: Type or namespace definition, or end-of-file expected C# 错误:cs(22,1):错误 CS1022:类型或命名空间定义,或预期文件结尾 - C# Error : cs(22,1): error CS1022: Type or namespace definition, or end-of-file expected Assets\\Scripts\\InGamePanel.cs(6,1):错误 CS1022:类型或命名空间定义,或预期的文件结尾 - Assets\Scripts\InGamePanel.cs(6,1): error CS1022: Type or namespace definition, or end-of-file expected 错误 CS1513:} 预期和 CS1022:预期文件结束 - 但文件对我来说看起来不错 - Error CS1513: } expected & CS1022: End-of-file expected - But file looks fine to me Unity 给出“类型或命名空间定义,或预期文件结尾”错误 - Unity gives “Type or namespace definition, or end-of-file expected” error 类型或命名空间定义,或预期的文件结尾 (22,1) (UNITY) - Type or namespace definition, or end-of-file expected (22,1) (UNITY) 类型或名称空间定义,或预期的文件结尾 - Type or namespace definition, or end-of-file expected Unity C# 错误:“类型或命名空间定义,或预期文件结尾” - Unity C# Error: “Type or namespace definition, or end-of-file expected”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM