0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Unity2D】スペースキーでジャンプさせる

0
Last updated at Posted at 2020-10-19

スペースキーの入力を受けとる

update関数の中にGetKeyDownでspaceキーの入力を受け取ります

void Update() {
  if (Input.GetKeyDown("space"))
          {

          }
}

Jump関数を作成

自身のRigidbody2Dを取得し、上方向に力を加えます。

Rigidbody2D rigidbody2D;

 void Jump()
    {
        // 上方向に力を加える
        rigidbody2D.AddForce(Vector2.up * 400);
    }

Jump関数を呼びだす

void Update() {
  if (Input.GetKeyDown("space"))
          {
            Jump();
          }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?