プレーヤーを動かして、ポイントとなるオブジェクトにぶつかれば、その位置を取得。
スペースキーを押せば、その位置に戻るという仕組みを、スクリプトで書いてみましょう。

関連記事:
ぶつかると最初からスタート
別オブジェクトの位置を取得する
ぶつかった位置を取得
Plane、Cube、Sphereを作成します。
CubeとSphereはわかりやすいようにカラーをつけます。
それぞれ地上に出して、距離を取ります。

Cubeにリジッドボディを追加します。

CubeMove.csを作成し、Cubeに追加します。

CubeMove.csを記述します。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class CubeMove : MonoBehaviour {   private float speed = 3.0f;   private Vector3 setPosition;     void Update()     {         float dx = Input.GetAxis("Horizontal") * Time.deltaTime * speed;         float dz = Input.GetAxis("Vertical") * Time.deltaTime * speed;         transform.position = new Vector3 (             transform.position.x + dx, transform.position.y, transform.position.z + dz         );         if(Input.GetKeyDown("space"))         {           this.transform.position = setPosition;         }     }     void OnCollisionEnter(Collision other)     {       if(other.gameObject.name == "Sphere")       {         setPosition = this.transform.position;       }     } } | 
ゲームプレイして、まずはSphereにぶつかります。
これで、ぶつかった場所の座標情報を取得。
他の場所へ移動し、スペースキーを押せば、Sphereにぶつかった場所へ戻ります。

関連記事:
ぶつかると最初からスタート
別オブジェクトの位置を取得する
 
	   
         
         
           
         
           
        