LoginSignup
2
2

More than 3 years have passed since last update.

Unityで簡単な玉転がしをしてみる(1:ボード動かし編)

Posted at

初めて記事を書きます。どうもです。
最近、何度も挫折しかけたUnityで簡単なゲームを作ろうを奮闘しています。
ほんとーに簡単なものですが、現段階までをまとめてみました。
ezgif.com-gif-maker.gif

こんな感じの簡単な玉転がしゲームを作ってますので、載せていきます。

ボードを動かす

キャプチャ.PNG

3Dオブジェクト上にCubeを配置します。そして横に広げます。
ezgif.com-gif-maker (1).gif
次に上のように↑↓→←でボードを回転させるスクリプトを紹介します。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class move_board : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }

    void Update()
    {
        float sense=0.2f;
        float moveHorizontal=Input.GetAxis("Horizontal");
        float moveVertical=Input.GetAxis("Vertical");


        transform.Rotate(moveHorizontal*sense,0,moveVertical*sense);   
    }
}

スクリプトの説明をします。

float moveHorizontal=Input.GetAxis("Horizontal");
float moveVertical=Input.GetAxis("Vertical");

ここは、それぞれ上下と右左の入力を取得します。-1~1までの値をとります。

float sense=0.2f;
~~
transform.Rotate(moveHorizontal*sense,0,moveVertical*sense);

※~~は途中のコードを飛ばしていることを示します。
senseとは回転する感度を示す変数です。これをそのままRotateにて掛けます。

完成

ezgif.com-gif-maker (1).gif

ボードは動かせましたでしょうか?次回はまた更に機能を追加していきます。

2
2
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
2
2