If you notice when you restore you are facing a different direction than when you saved. To fix this you can use something like this:
using System;
using UnityEngine;
namespace RPG.Saving
{
[System.Serializable]
public class SerializableTransform
{
float px, py, pz;
float rx, ry, rz, rw;
public SerializableTransform(Transform transform)
{
px = transform.position.x;
py = transform.position.y;
pz = transform.position.z;
rx = transform.rotation.x;
ry = transform.rotation.y;
rz = transform.rotation.z;
rw = transform.rotation.w;
}
public Tuple<Vector3, Quaternion> ToTransform()
{
return new Tuple<Vector3, Quaternion>(new Vector3(px, py, pz), new Quaternion(rx, ry, rz, rw));
}
}
}
and then use it in the mover like this:
public object CaptureState()
{
return new SerializableTransform(transform);
}
public void RestoreState(object state)
{
if (state is SerializableTransform posRot)
{
GetComponent<NavMeshAgent>().enabled = false;
transform.position = posRot.ToTransform().Item1;
transform.rotation = posRot.ToTransform().Item2;
GetComponent<NavMeshAgent>().enabled = true;
}
}