Unityでの移動量指定の移動方法について
Unityエンジンでは、移動は次のような2つの方法があります。
移動方法
- 方法1
transform.positionでの指定
オブジェクトの場所を代入できます。現在地に移動量をプラスして再度代入することで移動量での指定ができるようになります - 方法2
transform.Translate()メソッドでの指定
移動する量を引数に取れます。移動先の位置ではなので注意しましょう。
Unityエディターの初期状態

Unityエディターでの移動後

コンソールウィンドウの表示

移動のイメージ

方法1のコード
Vector3 diff = new Vector3(1, 0, 0);
transform.position += diff;
Debug.Log(transform.position);
方法2のコード
Vector3 diff = new Vector3(1, 0, 0);
transform.Translate(diff);
Debug.Log(transform.position);
ディスカッション
コメント一覧
まだ、コメントがありません