Sound + somewhat game loop
This commit is contained in:
parent
29e5e48aee
commit
1d6a879755
33 changed files with 1572 additions and 595 deletions
|
@ -17,7 +17,7 @@ public class Buttons : MonoBehaviour
|
|||
|
||||
public void PlayGame()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("Start Scene");
|
||||
GameManager.Instance.GoNextLevel();
|
||||
}
|
||||
|
||||
public void LaunchSettings()
|
||||
|
|
|
@ -22,7 +22,15 @@ public class CameraMouvement : MonoBehaviour
|
|||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
var mouvement = moveSpeed * Time.deltaTime * (new Vector3(_moveInput.y, 0, -_moveInput.x));
|
||||
transform.Translate(transform.TransformVector(mouvement), Space.World);
|
||||
var mouvement = (new Vector3(_moveInput.x, 0, _moveInput.y));
|
||||
var worldSpaceMouvement = transform.TransformVector(mouvement);
|
||||
var realMovement = Vector3.ProjectOnPlane(worldSpaceMouvement, Vector3.up);
|
||||
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0.0)
|
||||
{
|
||||
realMovement += Input.GetAxis("Mouse ScrollWheel") * 20.0f * transform.forward;
|
||||
}
|
||||
|
||||
transform.Translate(moveSpeed*Time.deltaTime*realMovement, Space.World);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,16 +8,15 @@ public class Crown : MonoBehaviour
|
|||
public event Action OnClicked;
|
||||
public bool crowned=false;
|
||||
[SerializeField] TextMeshProUGUI texte;
|
||||
|
||||
|
||||
[SerializeField] private Camera _camera;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
|
||||
[SerializeField] private GameObject startButton;
|
||||
private Camera _camera;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
texte.enabled = false;
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
public void StartCrown()
|
||||
|
|
|
@ -10,7 +10,7 @@ public class MonoBehaviourSingletonPersistent<T> : MonoBehaviour
|
|||
if (Instance == null) {
|
||||
Instance = this as T;
|
||||
Instance.name = typeof(T).Name;
|
||||
DontDestroyOnLoad (this);
|
||||
DontDestroyOnLoad (gameObject);
|
||||
} else {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ using UnityEngine.SceneManagement;
|
|||
public class GameManager : MonoBehaviourSingletonPersistent<GameManager>
|
||||
{
|
||||
[SerializeField] private List<string> levelNames;
|
||||
[SerializeField] private List<string> levelMusics;
|
||||
[SerializeField] private List<int> levelsMoney;
|
||||
int current_level = -1;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
GoNextLevel();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
@ -57,6 +57,7 @@ public class GameManager : MonoBehaviourSingletonPersistent<GameManager>
|
|||
current_level++;
|
||||
SetGlobals(current_level);
|
||||
SceneManager.LoadScene(levelNames[current_level]);
|
||||
SoundManager.Instance.PlayMusic(levelMusics[current_level]);
|
||||
}
|
||||
|
||||
throw new Exception("Bro there is no next level like stop pls");
|
||||
|
|
|
@ -1,36 +1,61 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[Serializable]
|
||||
public class SoundEntry
|
||||
{
|
||||
public string Key;
|
||||
public AudioClip Value;
|
||||
}
|
||||
|
||||
public class SoundManager : MonoBehaviourSingletonPersistent<SoundManager>
|
||||
{
|
||||
// Audio players components.
|
||||
public AudioSource EffectsSource;
|
||||
public AudioSource MusicSource;
|
||||
|
||||
public Dictionary<string, AudioClip> Sounds;
|
||||
|
||||
// Play a single clip through the sound effects source.
|
||||
public void Play(AudioClip clip)
|
||||
|
||||
public List<SoundEntry> SoundsList;
|
||||
private Dictionary<string, AudioClip> soundsDictionary;
|
||||
|
||||
|
||||
new void Awake()
|
||||
{
|
||||
EffectsSource.clip = clip;
|
||||
base.Awake();
|
||||
// Convert the List to a Dictionary at runtime for easier access
|
||||
soundsDictionary = new Dictionary<string, AudioClip>();
|
||||
foreach (var entry in SoundsList)
|
||||
{
|
||||
if (!soundsDictionary.ContainsKey(entry.Key))
|
||||
{
|
||||
soundsDictionary.Add(entry.Key, entry.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioClip GetSound(string key)
|
||||
{
|
||||
print(soundsDictionary.Count);
|
||||
AudioClip clip = soundsDictionary.TryGetValue(key, out var value) ? value : null;
|
||||
if (clip == null)
|
||||
{
|
||||
Debug.LogError($"Sound {key} not found");
|
||||
}
|
||||
return clip;
|
||||
}
|
||||
|
||||
public void Play(string keyName)
|
||||
{
|
||||
EffectsSource.clip = GetSound(keyName);
|
||||
EffectsSource.Play();
|
||||
}
|
||||
|
||||
// Play a single clip through the music source.
|
||||
public void PlayMusic(AudioClip clip)
|
||||
public void PlayMusic(string keyName)
|
||||
{
|
||||
MusicSource.clip = clip;
|
||||
MusicSource.clip = GetSound(keyName);
|
||||
MusicSource.Play();
|
||||
}
|
||||
|
||||
// Play a random clip from an array, and randomize the pitch slightly.
|
||||
public void RandomSoundEffect(params AudioClip[] clips)
|
||||
{
|
||||
int randomIndex = Random.Range(0, clips.Length);
|
||||
|
||||
EffectsSource.clip = clips[randomIndex];
|
||||
EffectsSource.Play();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SoundSettings : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public AudioSource source;
|
||||
public AudioClip clip;
|
||||
public string clipname;
|
||||
public bool isLoop;
|
||||
public bool playOnAwake;
|
||||
|
||||
[SerializeField] Slider slider;
|
||||
[SerializeField] AudioMixer audioMixer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SoundManager.Instance.PlayMusic("wait");
|
||||
}
|
||||
|
||||
public void SetVolume(float value)
|
||||
{
|
||||
|
@ -20,8 +20,7 @@ public class SoundSettings : MonoBehaviour
|
|||
value = 0.01f;
|
||||
}
|
||||
RefreshSlider(value);
|
||||
PlayerPrefs.SetFloat("Saved Maseter Volume", value);
|
||||
audioMixer.SetFloat("Master Volume", Mathf.Log10(value / 100) * 20f);
|
||||
SoundManager.Instance.MusicSource.volume = value;
|
||||
}
|
||||
|
||||
public void SetVolumeFromSlider()
|
||||
|
|
|
@ -3,10 +3,15 @@ using UnityEngine.AI;
|
|||
|
||||
public class UnitPlacement : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Camera _camera;
|
||||
private Camera _camera;
|
||||
public Vector3 lastPosition;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
public Vector3 MapPosition()
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
|
|
|
@ -13,7 +13,7 @@ public class MovementHandler : MonoBehaviour
|
|||
[SerializeField] private NavMeshAgent agent;
|
||||
[SerializeField] private bool followEnemy = true;
|
||||
[SerializeField] private float knockbackTime = 1.2f;
|
||||
private float _noNavMeshDeadTime = 6.0f;
|
||||
[SerializeField] private float _noNavMeshDeadTime = 3.0f;
|
||||
|
||||
[HideInInspector] public AbstractUnit TargetUnit {get; set; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue