Skip to content

Instantly share code, notes, and snippets.

@gamefish
Created April 1, 2022 13:21
Show Gist options
  • Save gamefish/a6b849991fc43771191aa3f2e281a5e9 to your computer and use it in GitHub Desktop.
Save gamefish/a6b849991fc43771191aa3f2e281a5e9 to your computer and use it in GitHub Desktop.
Save and load transform data, used to restore object transform
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