前提・実現したいこと
Unityで、オブジェクトの移動座標データ(x,y,z)をcsvファイルに書き出しましたが、現在は写真のように同じ座標も記録されてしまいます。座標データの記録を、座標が変わるごとに記録する方法を知りたいです。
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.IO; public class Log : MonoBehaviour { // Use this for initialization void Start() { string[] header = { "time", "x", "y", "z" }; } // Update is called once per frame void Update() { //ここに処理 StreamWriter sw; FileInfo fi; DateTime now = DateTime.Now; GameObject cube = GameObject.Find("Cube"); fi = new FileInfo(Application.dataPath + "/" + "xyz.csv"); sw = fi.AppendText(); sw.WriteLine($"{DateTime.Now},{cube.transform.position.x},{cube.transform.position.y},{cube.transform.position.z}"); sw.Flush(); sw.Close(); } }
試したこと
試しにこの文章を追加してみたのですが、
time += Time.deltaTime;
このようなエラーが出てしまいました。
Assets\Log.cs(24,9): error CS0103: The name 'time' does not exist in the current context
回答1件
あなたの回答
tips
プレビュー