今、Unityの勉強をしています。
現在のオブジェクトを回転させるプログラムを作成し、回転しているオブジェクトのRotationをエクセルに出力させています。
下記のコードでは、z座標しかエクセルに出力できていません。xとy座標も出力させたいのですが、カンマ区切りで一緒に出力させる方法がわかりません。
また、下記のコードではUnityのCubeのinspectorに表示されているRotation Zとエクセルに出力されている値が異なります。
inspectorには1秒ごとに0、5、10…のように5刻みの値が表示されます。
エクセルファイルには
0.043619
0.087156
0.130526
0.173648
0.21644
0.258819
0.300706
0.34202
のように値が入ります。
inspectorに表示されている値をエクセルファイルに出力させたいのですが、なぜかがわかりません。
よろしくお願いします。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Rotatecube : MonoBehaviour { 6 private float timeleft; 7 // Use this for initialization 8 void Start () { 9 10 } 11 12 // Update is called once per frame 13 void Update() 14 { 15 16 //だいたい1秒ごとに処理を行う 17 timeleft -= Time.deltaTime; 18 if (timeleft <= 0.0) { 19 timeleft = 1.0f; 20 21 //ここに処理 22 transform.Rotate(new Vector3(0, 0, 5)); 23 } 24 25 } 26}
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System.IO; 5 6public class log : MonoBehaviour 7{ 8 // Use this for initialization 9 void Start() 10 { 11 12 } 13 // Update is called once per frame 14 void Update() 15 { 16 //ここに処理 17 StreamWriter sw; 18 FileInfo fi; 19 20 GameObject cube = GameObject.Find("Cube"); 21 22 fi = new FileInfo(Application.dataPath + "/z.csv"); 23 sw = fi.AppendText(); 24 sw.WriteLine(cube.transform.rotation.z); 25 sw.Flush(); 26 sw.Close(); 27 } 28} 29
回答2件
あなたの回答
tips
プレビュー