Saving and Loading a GameObject’s position
The following script can be attached to a GameObject to save it’s position when it’s Destroyed (this happens when the scene is changed, and when the application quits), and load it’s position when the scene loads.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
using UnityEngine; public class SavePosition : MonoBehaviour { // Generate a unique ID for this GameObject. public string guid = System.Guid.NewGuid().ToString(); void Awake() { transform.localPosition = ES3.Load<Vector3>(guid, transform.localPosition); } void OnDestroy() { ES3.Save<Vector3>(guid, transform.localPosition); } } |