我正在尝试在Unity 3D中创建2D游戏,但出现以下错误:
解析错误:仅赋值,调用,递增,递减,等待和新对象表达式可以用作语句
我已按照指南进行操作,但仍然出现错误。
我的代码:
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;
!=
是不等式的算子。如果双方不相等,则返回true;如果双方相等,则返回false。它的对应者是==
操作员。
您最有可能打算在那里做的是
facingRight = !facingRight;
这将设置facingRight
为右侧的任何内容。这是!facingRight
,这当然会导致FaceingRight如果当前为false则为true,或者如果当前为true则为false。
通常,您可能希望包括在错误发生的那一行上的Ps。Unity应该告诉您有关这件事。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句