我在此错误<类型或命名空间定义或预期的文件结尾>遇到问题



我正在尝试将双跳添加到我的播放器中,但是我有这个错误

我在卷曲括号中遇到问题,因为在代码的乞讨中必须包含= public class playerController:monobehaviour {并以}

结尾

代码是这样,如果有人知道这一点,可以帮助您获得我的感谢

using System.Collections;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
    public float moveSpeed;
        private float moveSpeedStore;
    public float speedMultiplier;
    public float speedIncreaseMilestone;
    private float speedIncreaseMilestoneStore;
    private float speedMilestoneCount;
    private float speedMilestoneCountStore;
    public float jumpForce;
    public float jumpTime;
    private float jumpTimeCounter;
    private Rigidbody2D myRigidbody;
    private bool canDoubleJump;

    public bool grounded;
    public LayerMask whatIsGround;
    public Transform groundCheck;
    public float groundCheckSize;
    private Collider2D myCollider;
    private Animator myAnimator;
    private bool stoppedJumping;
    public GameManeger theGameManeger;
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        myCollider = GetComponent<Collider2D>();
        myAnimator = GetComponent<Animator>();
        jumpTimeCounter = jumpTime;
        speedMilestoneCount = speedIncreaseMilestone;
        moveSpeedStore = moveSpeed;
        speedMilestoneCountStore = speedMilestoneCount;
        speedIncreaseMilestoneStore = speedIncreaseMilestone;
        stoppedJumping = true;
    }
    void Update()
    {
        //grounded = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
        grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckSize, whatIsGround);
        if (transform.position.x > speedMilestoneCount)
        {
            speedMilestoneCount += speedIncreaseMilestone;
            speedIncreaseMilestone = speedIncreaseMilestone * speedMultiplier;
            moveSpeed = moveSpeed * speedMultiplier;
        }
        myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
        {
            if (grounded)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                stoppedJumping = false;
            }
        }
        if (Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0) && !stoppedJumping)
        {
            if (jumpTimeCounter > 0)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                jumpTimeCounter -= Time.deltaTime;
            }
            if (!grounded && canDoubleJump)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                stoppedJumping = false;
                canDoubleJump = false;
            }
        }
        if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
        {
            jumpTimeCounter = 0;
            stoppedJumping = true;
        }
        if (grounded)
        {
            jumpTimeCounter = jumpTime;
            canDoubleJump = true;
        }
        myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
        myAnimator.SetBool("Grounded", grounded);
    }
}
void OnCollisionEnter2D(Collision2D other)
{
    if (other.gameObject.tag == "killbox")
    {
        theGameManeger.RestartGame();
        moveSpeed = moveSpeedStore;
        speedMilestoneCount = speedMilestoneCountStore;
        speedIncreaseMilestone = speedIncreaseMilestoneStore;
    }
} 
 }
``````

检查您可能会错误地添加任何其他关闭括号},或者可能是一个丢失的括号,我建议使用IDE检测这些类型的错误。<<<<<<<<<<

我相信克里斯·杜纳威(Chris Dunaway(是正确的。您的代码中似乎有一个额外的卷发支撑,将最后一个方法推出了班级。

所以这个(如此强制格式化(:

[...]

    myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
    myAnimator.SetBool("Grounded", grounded);
}

}

void OnCollisionEnter2D(Collision2D other)
{
    if (other.gameObject.tag == "killbox")
    {
        theGameManeger.RestartGame();
        moveSpeed = moveSpeedStore;
        speedMilestoneCount = speedMilestoneCountStore;
        speedIncreaseMilestone = speedIncreaseMilestoneStore;
    }
}

}

应该是这样:

[...]

    myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
    myAnimator.SetBool("Grounded", grounded);
}
void OnCollisionEnter2D(Collision2D other)
{
    if (other.gameObject.tag == "killbox")
    {
        theGameManeger.RestartGame();
        moveSpeed = moveSpeedStore;
        speedMilestoneCount = speedMilestoneCountStore;
        speedIncreaseMilestone = speedIncreaseMilestoneStore;
    }
}

}

相关内容

  • 没有找到相关文章

最新更新