Add options menu and sound volume options logic
This commit is contained in:
parent
dfed2cc0e4
commit
91482820da
5 changed files with 1384 additions and 12 deletions
2
.erp
2
.erp
|
@ -5,7 +5,7 @@
|
||||||
<resetOnSceneChange>false</resetOnSceneChange>
|
<resetOnSceneChange>false</resetOnSceneChange>
|
||||||
<debugMode>false</debugMode>
|
<debugMode>false</debugMode>
|
||||||
<EditorClosed>true</EditorClosed>
|
<EditorClosed>true</EditorClosed>
|
||||||
<LastTimestamp>1677866565</LastTimestamp>
|
<LastTimestamp>1677873349</LastTimestamp>
|
||||||
<LastSessionID>7184246594242351147</LastSessionID>
|
<LastSessionID>7184246594242351147</LastSessionID>
|
||||||
<Errored>false</Errored>
|
<Errored>false</Errored>
|
||||||
</ERPSettings>
|
</ERPSettings>
|
File diff suppressed because it is too large
Load diff
|
@ -82,7 +82,6 @@ public class GameStateManager : MonoBehaviour
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsGamePlaying()
|
public bool IsGamePlaying()
|
||||||
|
|
|
@ -172,12 +172,16 @@ public class Player : MonoBehaviour, IKitchenObjectParent
|
||||||
// set isWalking to true if moveDir is not (0,0,0)
|
// set isWalking to true if moveDir is not (0,0,0)
|
||||||
isWalking = moveDir != Vector3.zero;
|
isWalking = moveDir != Vector3.zero;
|
||||||
|
|
||||||
|
if (isWalking)
|
||||||
|
{
|
||||||
float rotateSpeed = 10f;
|
float rotateSpeed = 10f;
|
||||||
// smothly rotate towards moveDir with a Slerp smoothed operation.
|
// smothly rotate towards moveDir with a Slerp smoothed operation.
|
||||||
// Slerp is for like rotations while Lerp is for positions
|
// Slerp is for like rotations while Lerp is for positions
|
||||||
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
|
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void SetSelectedCounter(BaseCounter selectedCounter)
|
private void SetSelectedCounter(BaseCounter selectedCounter)
|
||||||
{
|
{
|
||||||
this.selectedCounter = selectedCounter;
|
this.selectedCounter = selectedCounter;
|
||||||
|
|
|
@ -5,13 +5,19 @@ using UnityEngine;
|
||||||
public class SoundManager : MonoBehaviour
|
public class SoundManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private const string PLAYER_PREFS_SFX_VOLUME = "SFXVolume";
|
||||||
|
|
||||||
public static SoundManager Instance { get; private set; }
|
public static SoundManager Instance { get; private set; }
|
||||||
|
|
||||||
[SerializeField] private AudioClipsRefsSO audioClipsRefsSO;
|
[SerializeField] private AudioClipsRefsSO audioClipsRefsSO;
|
||||||
|
|
||||||
|
private float volume;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
|
volume = PlayerPrefs.GetFloat(PLAYER_PREFS_SFX_VOLUME, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
|
@ -64,9 +70,9 @@ public class SoundManager : MonoBehaviour
|
||||||
PlaySound(audioClipArray[Random.Range(0, audioClipArray.Length)], position, volume);
|
PlaySound(audioClipArray[Random.Range(0, audioClipArray.Length)], position, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlaySound(AudioClip audioClip, Vector3 position, float volume = 1f)
|
private void PlaySound(AudioClip audioClip, Vector3 position, float volumeMultiplier = 1f)
|
||||||
{
|
{
|
||||||
AudioSource.PlayClipAtPoint(audioClip, position, volume);
|
AudioSource.PlayClipAtPoint(audioClip, position, volumeMultiplier * volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayFootsteps(Vector3 position, float volume)
|
public void PlayFootsteps(Vector3 position, float volume)
|
||||||
|
@ -74,4 +80,21 @@ public class SoundManager : MonoBehaviour
|
||||||
PlaySound(audioClipsRefsSO.footstep, position, volume);
|
PlaySound(audioClipsRefsSO.footstep, position, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeVolume()
|
||||||
|
{
|
||||||
|
volume += .1f;
|
||||||
|
|
||||||
|
if (volume >= 1.1f) {
|
||||||
|
volume = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerPrefs.SetFloat(PLAYER_PREFS_SFX_VOLUME, volume);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetVolume()
|
||||||
|
{
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue