Created
April 1, 2022 13:21
-
-
Save gamefish/a6b849991fc43771191aa3f2e281a5e9 to your computer and use it in GitHub Desktop.
Save and load transform data, used to restore object transform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class SaveLoadTransform : MonoBehaviour | |
{ | |
Vector3 savedLocalPosition; | |
Quaternion savedLocalRotation; | |
Vector3 savedLocalScale; | |
Transform savedParent; | |
public void Save() | |
{ | |
savedLocalPosition = transform.localPosition; | |
savedLocalRotation = transform.localRotation; | |
savedLocalScale = transform.localScale; | |
savedParent = transform.parent; | |
} | |
public void Load() | |
{ | |
transform.SetParent(savedParent); | |
transform.localScale = savedLocalScale; | |
transform.localPosition = savedLocalPosition; | |
transform.localRotation = savedLocalRotation; | |
} | |
// Start is called before the first frame update | |
void Start() | |
{ | |
Save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment