I’m working on a rhythm game in Unity where I store the information needed for a given chart in a JSON file. While information like tempo, name, and an array of notes are fairly straightforward, I’ve been lost when it comes to storing a reference to an MP3 file that contains the audio I want to play alongside a rhythm chart.
With Unity, I’m using a custom class that stores the data that matches the file:
using UnityEngine;
[System.Serializable]
public class MusicChart
{
public string name;
public float startDelay;
public float tempo;
public float finishBeat;
public Timing[] timings;
}
Everything here works as intended, I just need something extra to append to the JSON file and this class that will make it work. Apologies for my ignorance, I’m both new to Unity and not well-versed in any complexities JSON might have. I figure the idea of storing the path as a string, then reading that path in on a script in Unity would work, but I don’t know how to do the latter part.
2
Answers
There are a few options:
string musicPath
field to your class.In all cases you will need to know how read and use the stream representing the mp3 data.
U can convert mp3 file to Base64String and avoiding loosing it :
use This method to To play mp3 File :