【问题标题】:Error in unity3D: Parser errorunity3D 中的错误:解析器错误
【发布时间】:2014-01-25 21:06:33
【问题描述】:

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

解析错误:只有assignments、call、increment、decrement、await和new对象表达式可以作为语句使用

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

我的代码:

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;
}
    }

【问题讨论】:

    标签: c# unity3d computer-science game-engine


    【解决方案1】:

    这是由以下语句引起的

    facingRight != facingRight;
    

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

    你最有可能打算在那里做的是

    facingRight = !facingRight;
    

    这会将facingRight 设置为右侧的任何内容。这是!facingRight,如果它当前为假,这当然会导致 facesRight 变为真,如果当前为真则变为假。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      相关资源
      最近更新 更多