---
title: モバイルデバイス入力
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ja-jp/engine/6000.0/manual/input/legacy/mobile
latest_url: https://docs.unity.com/ja-jp/engine/7000.0/manual/input/legacy/mobile.md
last_updated: 2026-10-30
generated_at: 2026-12-02T17:13:38.838Z
locale: ja-jp
---

# モバイルデバイス入力

> モバイルデバイスでタッチスクリーン、加速度センサー、および位置データにアクセスするためのリファレンス。

> **Important:**
>
> このページでは、入力マネージャーシステムの一部について説明します。入力マネージャーシステムは古い機能の特徴であり、新しいプロジェクトには推奨されません。新しいプロジェクトのモバイルデバイス入力には、[Input System パッケージ](https://docs.unity3d.com/Packages/com.unity.inputsystem@latest?subfolder=/manual/index.html) を使用します。

***

モバイルデバイスでは、[入力](/engine/6000.0/script-reference/unityengine/input.md)クラスはタッチスクリーン、加速度センサー、地理的/位置入力へのアクセスを提供します。

モバイルデバイスのキーボードへのアクセスは、[モバイルキーボード](/engine/6000.0/manual/input/mobile-keyboard.md)を介して提供されます。

## マルチタッチ画面##multi-touch-screen

iPhone、iPad、およびiPod Touchデバイスは、画面に同時に触れる最大5本の指を追跡できます。[Input.touches](/engine/6000.0/script-reference/unityengine/input/touches.md) プロパティ配列にアクセスすると、最後のフレームで画面にタッチした各指の状態を取得できます。

Androidデバイスには、追跡する指の数に関する統一された制限はありません。代わりに、デバイスによって異なり、古いデバイスでは 2 本指でタッチするものから、新しいデバイスでは 5 本指でタッチするものまであります。

各指のタッチは [Input.Touch](/engine/6000.0/script-reference/unityengine/touch.md) データ構造体で表されます。

以下のスクリプト例では、ユーザーが画面をタップするたびにレイを発射する方法を示します。

```lang-cs
using UnityEngine;

public class TouchInput :MonoBehaviour
{
    GameObject particle;

    void Update()
    {
        foreach(Input.touches のタッチタッチ)
        {
            if (touch.phase == TouchPhase.Began)
            {
                // Construct a ray from the current touch coordinates
                Ray ray = Camera.main.ScreenPointToRay(touch.position);
                if (Physics.Raycast(ray))
                {
                    // Create a particle if hit
                    Instantiate(particle, transform.position, transform.rotation);
                }
            }
        }
    }
}
```

### マウスシミュレーション##mouse-simulation

ネイティブサポートに加えて、Unity iOS/Android はマウスシミュレーションを提供します。標準[入力](/engine/6000.0/script-reference/unityengine/input.md)クラスからマウス機能を使用できます。iOS/Android デバイスは、複数の指によるタッチをサポートするように設計されています。マウス機能を使用すると、1 本の指によるタッチのみがサポートされます。また、モバイルデバイスでの指によるタッチ操作は、あるエリアから別のエリアへ移動しても、その間の移動はありません。モバイルデバイスでのマウスシミュレーションは移動を提供するため、タッチ入力とは大きく異なります。開発の初期にはマウスシミュレーションを使用し、できるだけ早くタッチ入力を使用することをお勧めします。

### 加速度センサー##accelerometer

モバイルデバイスが移動すると、ビルトイン加速度センサーが3次元スペースの3つの主要軸に沿ってリニア加速度の変化を報告します。軸に沿った加速度は、ハードウェアによって G 値として直接報告されます。値が 1.0 の場合は、指定された軸に対するロードが約 +1g であることを表し、値が -1.0 の場合は -1g を表します。正面でデバイスを垂直に (ホーム ボタンを下に置いて) 持っている場合、X 軸は右側に沿って正の値になり、Y 軸は真上に向かって正の値になり、Z 軸は手前に向かって正の値になります。

加速度センサーの値は、[Input.acceleration](/engine/6000.0/script-reference/unityengine/input/acceleration.md) プロパティにアクセスして取得できます。

以下のスクリプト例では、加速度センサーを使用してオブジェクトを動かします。

```lang-cs
using UnityEngine;

public class Accelerometer :MonoBehaviour
{
    float スピード = 10.0f;

    void Update()
    {
        Vector3 dir = Vector3.zero;
        // we assume that the device is held parallel to the ground
        // and the Home button is in the right hand

        // remap the device acceleration axis to game coordinates:
        // 1) XY plane of the device is mapped onto XZ plane
        // 2) rotated 90 degrees around Y axis

        dir.x = -Input.acceleration.y;
        dir.z = Input.acceleration.x;

        // clamp acceleration vector to the unit sphere
        if (dir.sqrMagnitude > 1)
            dir.Normalize();

        // Make it move 10 meters per second instead of 10 meters per frame...
        dir *= Time.deltaTime;

        // Move object
        transform.Translate(dir * speed);
    }
}
```

### ローパスフィルター##low-pass-filter

加速度センサーの表示がぎこちない、ノイズが多い場合があります。信号にローパスフィルタリングを適用すると、信号を滑らかなにし、高頻度ノイズを除去することができます。

以下のスクリプトは、加速度センサー度センサーの読み取りにローパスフィルタリングを適用する方法を示しています。

```lang-cs
using UnityEngine;

public class LowPassFilterExample :MonoBehaviour
{
    float accelerometerUpdateInterval = 1.0f / 60.0f;
    float lowPassKernelWidthInSeconds = 1.0f;

    private float lowPassFilterFactor;
    private Vector3 lowPassValue = Vector3.zero;

    void Start()
    {
        lowPassFilterFactor = accelerometerUpdateInterval / lowPassKernelWidthInSeconds;
        lowPassValue = Input.acceleration;
    }

    private void Update()
    {
        lowPassValue = LowPassFilterAccelerometer(lowPassValue);
    }

    Vector3 LowPassFilterAccelerometer(Vector3 prevValue)
    {
        Vector3 newValue = Vector3.Lerp(prevValue, Input.acceleration, lowPassFilterFactor);
        return newValue;
    }
}
```

`LowPassKernelWidthInSeconds` の値が大きいほど、フィルタリングされた値は現在の入力サンプルへの収束が遅くなります（逆も同様です）。

### 加速度センサーを読み取るときは、できるだけ正確に行ってください。どうすればよいですか?##i'd-like-as-much-precision-as-possible-when-reading-the-accelerometer.-what-should-i-do?

[入力.acceleration](/engine/6000.0/script-reference/unityengine/input/acceleration.md) 変数の読み取りとハードウェアのサンプリングは等しくありません。簡単に言えば、Unityはハードウェアを60Hzの頻度でサンプリングし、その結果を変数に格納します。実際には、状況はもうビット複雑です。CPU に大きな負荷がかかっている場合、加速度センサー度センサーのサンプリングは一定の間隔では行われません。その結果、システムは 1 つのフレームで 2 サンプルをレポートし、次のフレームで 1 サンプルをレポートする場合があります。

フレーム中に加速度センサーによって実行されたすべての測定値にアクセスできます。以下のコードは、最後のフレーム内で収集されたすべての加速度センサー度センサーイベントの単純な平均を示しています。

```lang-cs
public class AccelerationEvents : MonoBehaviour
{ 
    void Update()
    {
        GetAccelerometerValue();
    }

    Vector3 GetAccelerometerValue()
    {
        Vector3 acc = Vector3.zero;
        float period = 0.0f;

        foreach(AccelerationEvent evnt in Input.accelerationEvents)
        {
            acc += evnt.acceleration * evnt.deltaTime;
            period += evnt.deltaTime;
        }
        if (period > 0)
        {
            acc *= 1.0f / period;
        }
        return acc;
    }
}
```
