ニュース

Top  >   6. GameObject・Component・Transform  >   Q, オブジェクトを特定の場所に瞬間移動させたい

Q, オブジェクトを特定の場所に瞬間移動させたい

2026/03/18

メインコンテンツへスキップ
< すべてのカテゴリに戻る

A,結論

transform.position を直接書き換えます。

原因 / 背景

Transform コンポーネントが座標(X,Y,Z)の値を保持しているためです。

実装 / 手順

new Vector3(x, y, z) を代入します。

サンプルコード

using UnityEngine;

public class TeleportToTarget : MonoBehaviour
{
    [SerializeField] private Transform destination;

    public void Teleport()
    {
        if (destination == null)
        {
            Debug.LogWarning("Destination is not assigned.");
            return;
        }

        transform.position = destination.position;
        transform.rotation = destination.rotation;
    }
}

※ 実機確認が必要な項目は、Editor だけで判断せず対象デバイスでも必ず動作確認してください。

難易度:Level 1(入門)
対象プラットフォーム:Unity
関連キーワード:位置,座標,指定,移動

Level 1-2 向けバナー