C# 错误CS1525:意外的符号“{”

C# 错误CS1525:意外的符号“{”,c#,unity3d,C#,Unity3d,我是编程新手,这是碰撞物理和刚体运动的代码,但当我保存脚本时unity显示了这一点。问题在第45行和第50行 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move : MonoBehaviour { public float moveSpeed; private Animator anim; private Rigidbody2D myRigidbody

我是编程新手,这是碰撞物理和刚体运动的代码,但当我保存脚本时unity显示了这一点。问题在第45行和第50行

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

public class Move : MonoBehaviour {
public float moveSpeed;

private Animator anim;
private Rigidbody2D myRigidbody;

private bool playerMoving;
private Vector2 lastMove;


// Use this for initialization
void Start () {
    anim = GetComponent<Animator>();
    myRigidbody = GetComponent<Rigidbody2D>();

}

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

    playerMoving = false;

    if(Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
    {
        //transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
        myRigidbody.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, myRigidbody.velocity.y); 
        playerMoving = true;
        lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f );
    }

    if(Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f )
    {
        //transform.Translate (new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
        myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, Input.GetAxisRaw("Vertical") * moveSpeed);
        playerMoving = true;
        lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
    }

    If(Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
    {
        myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.y);
    }

    If(Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f )
    {
        myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, 0f);
    }

    anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
    anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
    anim.SetBool("PlayerMoving", playerMoving);
    anim.SetFloat("LastMoveX", lastMove.x);
    anim.SetFloat("LastMoveY", lastMove.y);
}
}
这两个:

If(Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
...
If(Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f )
这也很容易让事情变得更清楚:

Console.WriteLine("Test") { ... }

因此,将If语句更改为If,它应该会工作得更好。

您正在使用大写字母I编写If语句,这将使其成为一个方法调用。使用If,而不是If。注意:我们在这里没有看到行号。请在代码中添加注释,就像下一行显示的错误Lasse Vågsæther Karlsen ty那样
Console.WriteLine("Test") { ... }