Answer the question
In order to leave comments, you need to log in
Why does NullReferenceException appear the first time?
The bottom line is that I create text documents and then write data to them, the first method checks if there is such a thing and if not, it creates it, the second method takes data from these text documents and places it in variables
public float MusicVolume = 0.4f, SoundVolume = 0.2f;
private void Test1(){
if(!Resources.Load("Data/MusicVolume")){
StreamWriter writer = new StreamWriter("Assets/Resources/Data/MusicVolume.txt", false);
writer.Write(MusicVolume);
writer.Close();
............................................
}
private void Test2(){
TextAsset TX;
string Value = "";
TX = Resources.Load("Data/MusicVolume") as TextAsset;
Value = TX.text.Replace(" ", "").Replace(',', '.'); // <---- ошибка сюда указывает, и все больше ошибок нету
MusicVolume = float.Parse(Value, CultureInfo.InvariantCulture);
TX = Resources.Load("Data/SoundVolume") as TextAsset;
Value = TX.text.Replace(" ", "").Replace(',', '.');
.....................................
NullReferenceException: Object reference not set to an instance of an object
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question