1
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 3 years have passed since last update.

【Unity】キー入力でオブジェクトを移動させる(自分用)

Posted at

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

public class inputmoov : MonoBehaviour
{
    public float speed = 3f;//インスペクターで動くスピードを帰れる・

    void Start()
    {

    }

    void Update()
    {
        float moveX = Input.GetAxis("Horizontal");//⇦⇨キーの入力
        float moveY = Input.GetAxis("Vertical");//↑↓の入力

        moveX *= Time.deltaTime * speed;
        moveY *= Time.deltaTime * speed;

        transform.position += new Vector3(moveX, 0, moveY);//動かしたい方向の軸に先程の変数を入れる

    }
}

このスクリプトを動かしたいオブジェクトにアタッチ。
終了。

1
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
1
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?