Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Script memory

Discussion in 'Scripting' started by SkyreX12, Mar 1, 2018.

  1. SkyreX12

    SkyreX12

    Joined:
    Jan 28, 2018
    Posts:
    4
    Is there any way to make the script can remember data and use it in several scenes?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You can move a game object (and its scripts) between scenes using DontDestroyOnLoad.

    You can use static variables..

    You can use scriptable objects.

    I would look into the first two to see what they are, and choose whichever sounds best for you. Later, if you're still interested, I'd recommend learning a bit about scriptable objects. :)
     
  3. busterlock

    busterlock

    Joined:
    Sep 26, 2015
    Posts:
    58
    If your plan is to do something like a "High Score" or similar, PlayerPrefs pretty much cut it. They are held intact every time you go back playing, and the memory is always kept (and can be deleted if you script it, too).

    https://docs.unity3d.com/ScriptReference/PlayerPrefs.html