gpt4 book ai didi

c# - unity3D错误: Parser error

转载 作者:太空宇宙 更新时间:2023-11-03 13:28:51 24 4
gpt4 key购买 nike

我尝试在 Unity 3D 中创建 2D 游戏,但出现以下错误:

Parse error: Only assignments, call, increment, decrement, await, and new object expressions can be used as a statement

我已按照指南进行操作,但仍然遇到错误。

我的代码:

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {

public float maxSpeed = 10f;
bool facingRight = true;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void FixedUpdate () {
float move = Input.GetAxis ("Horizontal");
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if(move > 0 &&! facingRight){
Flip ();
}
else if(move < 0 && facingRight){
Flip ();
}
}
void Flip () {
facingRight != facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}

最佳答案

那是下面语句造成的

facingRight != facingRight;

!= 是一个 inequality operator .如果两边不相等则返回 true,如果两边相等则返回 false。它的对应物是 == 运算符。

你最有可能想做的是

facingRight = !facingRight;

这会将 facingRight 设置为右侧的任何内容。即 !facingRight,这当然会导致 facingRight 在当前为 false 时变为 true,或者在当前为 true 时变为 false。

附言您通常可能希望包括错误发生在哪一行。 Unity 应该会告诉您这一点。

关于c# - unity3D错误: Parser error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21356250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com