現在unityについて学んでいるものです
今回,AudioListenerに入力された音の波形を表示するシーンを作成したのですがその値を実際の数値として確認したいため,txtに書き出してみたいと考えました.
以下のようなプログラムを書きました
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
using System.IO;
public class CSVmaker : MonoBehaviour
{
private int index;
private int count;
// Use this for initialization
public float[] data = new float[1024];
public int channel = 1;
StreamWriter sw = new StreamWriter(@"C:\data\test.txt", false, System.Text.Encoding.GetEncoding("shift_jis"));
internal float output;
void Start()
{
index = 0;
count = 0;
} // Update is called once per frame void Update() { AudioListener.GetOutputData(data, channel); sw.WriteLine(data); }
}
このままだと以下のようなエラーが出ます
IOException: Sharing violation on path C:\data\test.txt
CSVmaker..ctor () (at Assets/CSVmaker.cs:14)
NullReferenceException: Object reference not set to an instance of an object
CSVmaker.Update () (at Assets/CSVmaker.cs:36)
エラーの意味をググってみたのですがよくわかりませんでした
ファイルの指定先のtest.txtは作成済みです
回答1件
あなたの回答
tips
プレビュー