マウスランナータイプのゲームを作っています。マウスボタンをクリックしたときに壁を変更するためにキャラクターが必要です。私はそれを重力で働かせましたが、望ましくない影響を与えました。したがって、私は現在transform.positionを使って作業していますが、文字は1秒間だけ動いています(transform.positionはマウスボタンが実際にクリックされている間のみ有効です)。Unity - GetMouseButtonDownのときにx軸に沿って方向を変更
ちょうど少し動くのではなく、マウスクリックで方向を変える方法を教えてください。 whileループが必要なのですか、どこにいるのですか?
私のクラス:
//Variables used by the Player
public int flyingSpeed;
bool rightWall = true;
bool inAir = false;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
//Constantly moves the Players position along the Y-axis
if (inAir == false) {
if (Input.GetMouseButtonDown (0) && rightWall == true) {
transform.position += Vector3.left * flyingSpeed * Time.deltaTime;
rightWall = false;
inAir = true;
} else if (Input.GetMouseButtonDown (0) && rightWall == false) {
transform.position += Vector3.right * flyingSpeed * Time.deltaTime;
rightWall = true;
inAir = true;
}
}
}
void OnCollisionEnter2D(Collision2D coll) {
inAir = false;
}