Unity Tutorial : How to save data when moving between two scenes ( Using Player Prefs )

preview_player
Показать описание
Simple tutorial on how to save data when moving between two scenes!

In this tutorial, I will be using Player Prefs ( float ) to save the data in memory and fetch the data again when the new scene opens again.

If you enjoyed this video please leave a like and subscribe!

Thanks for watching cheers.

Song name:
Eels - I Need Some Sleep (Dwin Remix)
Рекомендации по теме
Комментарии
Автор

Howsite Guys,

Just finished with the second part of this video on playing music seamlessly across multiple scenes!

If you want to check it out:

catodevs
Автор

Dude you are helping us by making videos on topics that we all beginner wants to know, thank you

DauDaGamer
Автор

Amazing videos! Those videos really helped me out with the new game that I hope to release soon on Steam! Looking forward to the next tutorial.

uxe_yo
Автор

THANK YOU SO MUCH
its been painful to learn how to do this, you just solved one of my biggest issues

tsunamidev
Автор

Underrated video, seems like minor thing but its very important. Im sure that this video will help every viewer here and i hope u make another helpful video.

qwertypaszzz
Автор

Yess thank you bro! This really helped a lot

RumbleKnightYT
Автор

it works thanks :) i hope u drop the next tutorial soon!

evzyl
Автор

I think having it in a function that gets{} the values before switching scene is the correct way to do it rather than having them all in Update(). For example on slider you don't need that update that often, just takes up unnecessary memory and your only moving over the values on switching scene's?

coregamestudio
Автор

I'm trying to do this for a toggle but I haven't been able to figure out what I'm doing wrong all day.

It just keeps outputting true if it's toggled on or not.

explodingmonkey
Автор

When i switch from my main menu to level 1 the volume in level 1 switches the audio to 0, 5 and on the main menu o selected 0, 2

luckydenzel
Автор

I'm getting a compiler error. - Heres my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MainthemeScript : MonoBehaviour
{
// Start is called before the first frame update
public AudioSource AudioSource;

public Slider volumeSlider;

public float musicVolume = 1f;


void start()
{
AudioSource.volume = musicVolume;
musicVolume =
AudioSource.volume = musicVolume;
volumeSlider.value = musicVolume;
}

// Update is called once per frame
void Update()
{
AudioSource.volume = musicVolume;
PlayerPrefs.Setfloat("volume", musicVolume)
}
public void updateVolume (float volume)
{
musicVolume = volume;
}
}

HCs
Автор

You can also make real variables that saves between scenes by using static before public in your variable, but if you restart the game it resets tho.
EX:
static public testVariable;

Xofol
Автор

3:30
do you have to declare the volume variable some where first?

superdahoho
Автор

at first it didn't work for me but I changed the float to a static float and it worked (I'm using this for FOV)

dark_terion
Автор

YEEEEs finally i found the right thing ! Thanks

combatmedic
Автор

Let's say i have a slider on scene1, and I don't have it on scene2. I just need the slider value to use it on scene2. What would i do?

emirhanpakyardm
Автор

It works perfectly when I test it in unity. but when I export my project for android it doesn't save volume slider, do you have any idea what is going wrong?

quantummobilegames
Автор

my audio source didn't appear . why?? this is my script ...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MusicPlay : MonoBehaviour
{
private AudioSource AudioSource;

public Slider volumeSlide;

private float MusicVolume = 1f;

private void Start()
{
AudioSource.Play();
MusicVolume =
AudioSource.volume = MusicVolume;
volumeSlide.value = MusicVolume;
}



// Update is called once per frame
private void Update()
{
AudioSource.volume = MusicVolume;
PlayerPrefs.SetFloat("volume", MusicVolume);
}

public void Volumeupdater(float volume)
{
MusicVolume = volume;
}

public void MusicReset()
{

AudioSource.volume = 1;
volumeSlide.value = 1;
}

}

nrlafiefy
Автор

Hi can you please in a project that i have to found?

micheleguardabasso
Автор

Thanks for the tutorial! I'm getting this error though: "error CS0120: An object reference is required for the non-static field, method, or property 'AudioSource.Play()'"

pillemarisken