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: th-cam.com/video/Xtfe5S9n4SI/w-d-xo.html
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?
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.
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;
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.
Howsite bud, Just published the new video on how to play music seamlessly across multiple scenes ( part 3 of these videos ). Hope it is helpful :) th-cam.com/video/Xtfe5S9n4SI/w-d-xo.html
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 = PlayerPrefs.Getfloat("colume"); 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; } }
Howsite Bud, The line: "PlayerPrefs.SetFloat("volume", MusicVolume)" is missing the ';' at the end... so should be: void Update() { AudioSource.volume = MusicVolume; PlayerPrefs.SetFloat("volume", MusicVolume); } Hope that helps!
@@emirhanpakyardm9142 make a duplicate of the slider for every scene but make the sliders invisible where u dont want them, then pretend as if it is the original slider (put the audio source in the music player etc)
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?
You have 'private AudioSource AudioSource; ' This means you won't be able to add an audio source on the inspector. so change it to: public AudioSource AudioSource; This should work. Let me know if that solves your problem :)
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()'"
The volume slider option wont appear under my MusicControl thingy. Heres my script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MusicPlay : 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 = PlayerPrefs.Getfloat("colume"); 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; } }
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:
th-cam.com/video/Xtfe5S9n4SI/w-d-xo.html
Dude you are helping us by making videos on topics that we all beginner wants to know, thank you
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.
No problem Bru🤟 hope your game takes off on steam 🚀
THANK YOU SO MUCH
its been painful to learn how to do this, you just solved one of my biggest issues
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?
Exactly what I needed. Thanks man!
No problem!
3:30
do you have to declare the volume variable some where first?
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.
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;
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
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.
Thanks for the great feedback mate!
@@catodevs i hope you can create another vid like this but for HealthBar Slider. thanks for this helpful vid mate!
it works thanks :) i hope u drop the next tutorial soon!
Working on it! Will be ready soon 🤟
Howsite bud,
Just published the new video on how to play music seamlessly across multiple scenes ( part 3 of these videos ).
Hope it is helpful :)
th-cam.com/video/Xtfe5S9n4SI/w-d-xo.html
Yess thank you bro! This really helped a lot
Thanks Bro! You help me a lot!
how can i use it for toggle please ?
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 = PlayerPrefs.Getfloat("colume");
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;
}
}
Howsite Bud,
The line:
"PlayerPrefs.SetFloat("volume", MusicVolume)"
is missing the ';' at the end... so should be:
void Update()
{
AudioSource.volume = MusicVolume;
PlayerPrefs.SetFloat("volume", MusicVolume);
}
Hope that helps!
Works just fine. Thanks a bunch mate!
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?
Dont mind if I ask, have you found the solution to that? Having the same problem right now
Nvm, just found out how :D
@@philippgyarmati6638 no, unfortunately
@@philippgyarmati6638 oh tell me xD
@@emirhanpakyardm9142 make a duplicate of the slider for every scene but make the sliders invisible where u dont want them, then pretend as if it is the original slider (put the audio source in the music player etc)
YEEEEs finally i found the right thing ! Thanks
thank you so much bro)👍
thanks)) really useful
Thanks, waiting on the 2nd part.
Coming soon 🤟 will let you know
Hey Man,
Just finished with the 2nd part!
Hope it is helpful :)
th-cam.com/video/Xtfe5S9n4SI/w-d-xo.html
Hi can you please in a project that i have to found?
Works great ,thank you!
works fine thanks a lot dude
do you have a discord channel?
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)
Im like 10 months away from the post date if this comment, but fo you mind sharing how you created the FOV slider?
Finaly, thanks mate
Thank you very much!
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?
Not sure mate, have sliders ever worked on your phone ? If they have try compare what's different between the two
thanks, really usefull
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 = PlayerPrefs.GetFloat("volume");
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()
{
PlayerPrefs.DeleteKey("volume");
AudioSource.volume = 1;
volumeSlide.value = 1;
}
}
You have 'private AudioSource AudioSource; '
This means you won't be able to add an audio source on the inspector.
so change it to:
public AudioSource AudioSource;
This should work.
Let me know if that solves your problem :)
Making this for Player Stats . Plz help me .
SA representing :)
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()'"
Check if you’ve dragged the audio source onto the script component, you have to reference the public component used in the script
How to make that for mouse sensitivity
Hi bud, sorry for the late response.
Will have to make another video for that tutorial.
error in value bro
thanks
Thanks!
No more videos? ):
Coming soon. Just in the process of immigrating and stuff haha when I'm settled I'll be making more videos 🤟🏼
@@catodevs Nice!
Thanks
:D
The volume slider option wont appear under my MusicControl thingy. Heres my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MusicPlay : 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 = PlayerPrefs.Getfloat("colume");
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;
}
}
Thanks!!!!!
But india failed to maintain UNITY..
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Slider : MonoBehaviour
{
private AudioSource AudioSource;
public Slider volumeSlide;
private float MusicVolume = 1f;
private void Start()
{
AudioSource.Play();
MusicVolume = PlayerPrefs.GetFloat("volume");
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()
{
PlayerPrefs.DeleteKey("volume");
AudioSource.volume = 1;
volumeSlide.value = 1;
}
}
Thank you soooo much!