[英]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.