ゲームオブジェクトの向きを取得することができる変数です。
transform 変数に代入されているゲームオブジェクトの向きの情報が取得出来ます。
ゲームオブジェクトの正面の向きは、Transform.forward 変数で取得出来ます。
Scene ビューにあるゲームオブジェクトを選択したときに表示される、Z 軸向き(青色)の矢印(ベクトル)に相当する情報です。
この値はワールド座標系で正規化(長さが 1 の単位ベクトル)されたベクトルであり、それぞれ、(0, 0, 1) の値となります。
公式スクリプトリファレンスには、Vector3.forward 変数との違いについても記載されています。
<公式スクリプトリファレンスと翻訳>
Returns a normalized vector representing the blue axis of the transform in world space.
ワールド空間でのトランスフォームの青軸を表す正規化されたベクトルを返します。
The example below shows how to manipulate a GameObject’s position on the Z axis (blue axis) of the transform in world space.
以下の例は、ワールド空間でのトランスフォームの Z 軸 (青い軸) 上のゲームオブジェクトの位置を操作する方法を示しています。
Unlike Vector3.forward, Transform.forward moves the GameObject while also considering its rotation.
Vector3.forward とは異なり、Transform.forward は回転も考慮しながら GameObject を移動します。
When a GameObject is rotated, the blue arrow representing the Z axis of the GameObject also changes direction.
ゲームオブジェクトが回転すると、ゲームオブジェクトの Z 軸を表す青い矢印も方向が変わります。
Transform.forward moves the GameObject in the blue arrow’s axis (Z).
Transform.forward は、GameObject を青い矢印の軸 (Z) に沿って移動します。
For moving the GameObject on the Z axis while ignoring rotation, see Vector3.forward.
回転を無視して Z 軸上でゲームオブジェクトを移動するには、Vector3.forward を参照してください。
参考サイト
Unity公式スクリプトリファレンス
Transform-forward
ゲームオブジェクトの右の向きは Transform.right 変数から取得することができます。
Scene ビューにあるゲームオブジェクトを選択したときに表示される、X 軸向き(赤色)の矢印(ベクトル)に相当する情報です。
この値はワールド座標系で正規化された(長さが 1 の単位ベクトル)されたベクトルであり、それぞれ、(1, 0, 0) の値となります。
Vector3.up との違いも、Transform.forward 変数と同じで回転情報を参照するか、しないかにあります。
参考サイト
Unity公式スクリプトリファレンス
Transform-right
ここでは取り上げませんが、上方向の情報を取得できる Transform.up 変数も用意されています。
覚えておくと便利な変数群です。
参考サイト
ねこじゃらシティ 様
【Unity】オブジェクトの向きを取得する