mirror of
https://github.com/Kizuren/ShantiManti.git
synced 2025-12-21 21:16:04 +01:00
Refactored Sound script & removed an animation bug
This commit is contained in:
parent
a90f5fe421
commit
e51c6f4650
3 changed files with 14 additions and 14 deletions
|
|
@ -20,7 +20,7 @@ public class PlayerSaving : MonoBehaviour
|
|||
Debug.Log($"Saved level: {Level}, coins: {Coins}, tutorial: {HasCompletedTutorial}, cloudsMove: {MovingClouds}");
|
||||
}
|
||||
|
||||
public static void LoadPlayer()
|
||||
private static void LoadPlayer()
|
||||
{
|
||||
var data = SaveSystem.LoadPlayer();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class Pause : MonoBehaviour
|
|||
public GameObject Fire;
|
||||
public GameObject Image;
|
||||
|
||||
private static readonly int IsCrouching = Animator.StringToHash("IsCrouchingAnimationID");
|
||||
private static readonly int IsCrouchingAnimationID = Animator.StringToHash("IsCrouching");
|
||||
|
||||
public void IsPauseing()
|
||||
{
|
||||
|
|
@ -58,7 +58,7 @@ public class Pause : MonoBehaviour
|
|||
if(!IsPause) // if going back to the game
|
||||
{
|
||||
PlayerMovement.Crouch = false;
|
||||
animator.SetBool(IsCrouching, false);
|
||||
animator.SetBool(IsCrouchingAnimationID, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ public class SoundBar : MonoBehaviour
|
|||
{
|
||||
public static float SoundVolume = 0.75f;
|
||||
public AudioSource BackgroundMusic;
|
||||
public static float MusicTime = 0f; // Static variable to store the music time
|
||||
public static bool SceneReloaded = false; // Static variable to track if scene is reloaded
|
||||
private static float _musicTime; // Static variable to store the music time
|
||||
public static bool SceneReloaded; // Static variable to track if scene is reloaded
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
LoadSoundVolume();
|
||||
ApplySoundVolume();
|
||||
|
|
@ -17,38 +17,38 @@ public class SoundBar : MonoBehaviour
|
|||
if (SceneReloaded)
|
||||
{
|
||||
// If the scene has been reloaded before, continue playing from where it stopped
|
||||
BackgroundMusic.time = MusicTime;
|
||||
BackgroundMusic.time = _musicTime;
|
||||
}
|
||||
SceneReloaded = false;
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
if (SoundVolume != BackgroundMusic.volume)
|
||||
if (!Mathf.Approximately(SoundVolume, BackgroundMusic.volume))
|
||||
{
|
||||
SoundVolume = BackgroundMusic.volume;
|
||||
SaveSoundVolume();
|
||||
}
|
||||
|
||||
MusicTime = BackgroundMusic.time;
|
||||
_musicTime = BackgroundMusic.time;
|
||||
}
|
||||
|
||||
public static void SaveSoundVolume()
|
||||
private static void SaveSoundVolume()
|
||||
{
|
||||
PlayerPrefs.SetFloat("SoundVolume", SoundVolume);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
void LoadSoundVolume()
|
||||
private static void LoadSoundVolume()
|
||||
{
|
||||
if (PlayerPrefs.HasKey("SoundVolume"))
|
||||
{
|
||||
float savedVolume = PlayerPrefs.GetFloat("SoundVolume");
|
||||
var savedVolume = PlayerPrefs.GetFloat("SoundVolume");
|
||||
SoundVolume = savedVolume;
|
||||
}
|
||||
}
|
||||
|
||||
void ApplySoundVolume()
|
||||
private void ApplySoundVolume()
|
||||
{
|
||||
BackgroundMusic.volume = SoundVolume;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue