前提・実現したいこと
ButtonManeでキーボードで入力した数字を、LogScriptで作成したエクセルのファイルに入力した数字が表示されるようにしたいです。
例:5を入力→エクセルで5を表示
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class ButtonMane : MonoBehaviour { public GameObject[] buttons; bool aji; int i,j,tmp; public static int[] ary = Shuffle(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); private static System.Random rng; private static int[] Shuffle(int[] array) { if (rng == null) { rng = new System.Random(); } //重複なしランダム配列-------------------------------------------- if (array != null) { int n = array.Length; while (n > 1) { n--; int k = rng.Next(n + 1); int tmp = array[k]; array[k] = array[n]; array[n] = tmp; } } //重複なしランダム配列ここまで--------------------------------------- return array; } public static int[] ply = new int[] { 9, 9, 9, 9, 9, 9, 9, 9, 9 }; // Start is called before the first frame update void Start() { aji = true; } // Update is called once per frame void Update() { //プレイヤー配列作成--------------------------------- if (aji) { if (Input.GetKeyDown(KeyCode.Alpha0)) { ply[i] = 0; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha1)) { ply[i] = 1; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha2)) { ply[i] = 2; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha3)) { ply[i] = 3; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha4)) { ply[i] = 4; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha5)) { ply[i] = 5; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha6)) { ply[i] = 6; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha7)) { ply[i] = 7; i = i + 1; } if (Input.GetKeyDown(KeyCode.Alpha8)) { ply[i] = 8; i = i + 1; } if (i == 5) { aji = false; } } //プレイヤー配列作成ここまで------------------------------------ } }
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; public class LogScript : MonoBehaviour { ButtonMane script; int[] log = new int[] { 9, 9, 9, 9, 9, 9, 9, 9, 9 }; string datetimeStr1 = System.DateTime.Now.ToString("yyyy年MM月dd日"); string datetimeStr2 = System.DateTime.Now.ToString("yyyy年MM月dd日HH時mm分ss秒"); bool ikr; private void Start() { ikr = true; for (int i = 0; i < 9; i++) { log[i] = ButtonMane.ary[i]; } } private void LateUpdate() { if (ikr) { for (int i = 0; i < 5; i++) { pro[i] = ButtonMane.ply[i]; } if (File.Exists("log") == false) { Directory.CreateDirectory("log"); } if (File.Exists("log/" + datetimeStr1 + "") == false) { Directory.CreateDirectory("log/" + datetimeStr1 + ""); } StreamWriter sw; sw = new StreamWriter("log/" + datetimeStr1 + "/" + datetimeStr2 + ".csv", true); for (int i = 0; i < 5; i++) { sw.WriteLine(log[i]); } sw.Close(); ikr = false; } } }
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー