PlayerPrefs Autosave [SOLVED]

Hello, guys!

My aim is to set autosave and autoload for (my sort of) text-game. All I need to do is save Content position in Scroll.

I would really appreciate if someone could give a peek on my script :wink:

The console doesn’t throw errors, but nevertheless, the script doesn’t work. In spite of that Debug.Log appears correctly. (I attach this script to Main Camera).

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AutoSaveLoad : MonoBehaviour {

    public GameObject content;

      private void Start()

    void OnEnable()
        print("Application was loaded");

    void OnApplicationQuit()
        Debug.Log("Application was saved");

    public void Save()
        PlayerPrefs.SetFloat("ContentX", content.transform.position.x);
        PlayerPrefs.SetFloat("ContentY", content.transform.position.y);
        Debug.Log("Content position is saved in PlayerPrefs");
    public void Load()
        transform.position = new Vector2(PlayerPrefs.GetFloat("ContentX"), PlayerPrefs.GetFloat("ContentY"));
        Debug.Log("Content position is loaded from PlayerPrefs");


Thank you!

Hello, your key must be the same in the get and in the set. change your key since one is in caps and the other is not.

Actually it is working as it should. your not debugging the info you want to see for 1 and 2, your not calling the data in the start or in OnEnable rather in this case to see if it did save. so how do you know it isn’t working? all signs say yes it is.

Guys! All I had to do is attach this script not to Man Camera, but to Content Game Object itself. It works! Thank you all for responding and help! Cheerio!

thing i found your error, your doing new Vector2 on this.transform.position NOT the content.transform.position

if you want that game object to move, then get rid of your content variable and just use

this.gameobject.transform.postition x and this.gameobject.transform.position.y