前提・実現したいこと
宣言した配列の中身を上書きする方法が知りたいです。
int[] ply = new int[] { 9, 9, 9, 9, 9, 9, 9, 9, 9 };
この中身を、上書きしたいです。
LogScriptで上書きした配列を使用したいです。
発生している問題・エラーメッセージ
LogScriptの表示結果が 9,9,9 となってしまう。
該当のソースコード
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public class BCheck : MonoBehaviour
{
public GameObject[] buttons;
bool aji; int i; 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 == 8) { 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] = BCheck.ply[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); sw.WriteLine("test" + 100); for (int i = 0; i < 9; i++) { sw.WriteLine(log[i]); } sw.Close(); ikr = false; } }
C#
試したこと
ネットで調べてみましたが、わかりませんでした。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答3件
あなたの回答
tips
プレビュー