feat: load dynamically level music

This commit is contained in:
2025-02-09 19:37:37 +01:00
parent a5cdd3ada1
commit 707dee5063
70 changed files with 230 additions and 122 deletions

View File

@@ -1,13 +1,14 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using System.IO;
using UnityEngine.Audio;
public class Player : MonoBehaviour
{
public Rigidbody2D rigidBody;
public GameObject playerObject;
public ParticleSystem particle;
public LevelLoader levelLoader;
public LevelsLoader levelsLoader;
public bool isColliding = true;
public AudioSource audioSource;
@@ -17,26 +18,24 @@ public class Player : MonoBehaviour
public void Start()
{
// levelLoader = GameObject.FindGameObjectWithTag("LevelLoader").GetComponent<LevelLoader>();
levelsLoader = GameObject.FindGameObjectWithTag("LevelsLoader").GetComponent<LevelsLoader>();
string musicPath = Path.Combine("Musics", Path.GetFileNameWithoutExtension(levelsLoader.level.MusicName));
AudioClip clip = Resources.Load<AudioClip>(musicPath);
if (clip == null)
{
Debug.LogError("Music file not found at: " + musicPath);
}
else
{
audioSource.clip = clip;
audioSource.Play();
}
var mainModule = particle.main;
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
particle.transform.parent = null;
// if (levelLoader.level != null)
// {
// string musicPath = Path.Combine("Musics", Path.GetFileNameWithoutExtension(levelLoader.level.MusicPath));
// AudioClip clip = Resources.Load<AudioClip>(musicPath);
// if (clip != null)
// {
// audioSource.clip = clip;
// audioSource.Play();
// }
// else
// {
// Debug.LogError("Failed to load music: " + musicPath);
// }
// }
Invoke(nameof(EnableInput), 0.1f);
}