Saving and loading

I’m trying to make a save system for my game, but having no luck in actually loading.
(The code is linked to buttons for saving and loading, as well as the player.)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SaveSysten2 : MonoBehaviour
{
    public PlayerController thePlayer;
    public float savedeyes;
    public bool aaa;
    public bool bbb;
    public Vector2 startDirection;
    // Use this for initialization
    void Start()
    {
        aaa = true; 
    }
    // Update is called once per frame
    void Update()
    {
        startDirection = thePlayer.lastMove;
        if (aaa)
        {
            LoadData();
            aaa = false;
        }
        if (bbb)
        {
            SaveData(thePlayer);
            bbb = false;
        }
    }
    public void Aaa()
    {
        aaa = true;
    }
    public void Bbb()
    {
        bbb = true;
    }
    public static void SaveData(PlayerController player)
    {
        PlayerPrefs.SetFloat("x", player.transform.position.x);
        PlayerPrefs.SetFloat("y", player.transform.position.y);
        PlayerPrefs.SetFloat("eyes", player.eyes);
       
    }
    public void LoadData()
    {
        float x = PlayerPrefs.GetFloat("x");
        float y = PlayerPrefs.GetFloat("y");
        float eyes = PlayerPrefs.GetFloat("eyes");
        thePlayer.eyes = eyes;
        thePlayer.A = x;
        thePlayer.B = y;
       
        Debug.Log("Data actually laoded");
    }
}

The part of the player controller that loads is below.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{

public float A;
public float B;
public float eyes;

void wakeUp()
    {
        Vector2 newPose = new Vector2(A, B);
        transform.position = newPose;
    }
}

Like I said, the problem is loading the saved data. I think it’s saving properly, since I’ve tested it with Debug.Log.

I don’t see where you call wakeUp() to actually use the restored positions in A,B.

Are you trying to call Awake?

Oh god how did I miss that lol tysm

1 Like