前提・実現したいこと
GameSystem.scにOnGUI.Buttonを8つ作り、ゲームシーンの8つのボタンのどれかを押すとクローンオブジェクトが数個出るようにしました。
ゲーマーがそのオブジェクトの数を数えてキーボードからその数を打ち込んでゲームシーンに表示出来るように、InputFiedlを作成しました。
*InputFieldのTextでは見にくいので、InpuManager.scを付けてその中にScore Textを作りました。
発生している問題・エラーメッセージ
ボタンを押すとオブジェクトは現れるのですが、打ち込んだ数字がゲームシーンに表示されません。
エラーメッセージ InspectorのScoreTextに付けているScoreは0のままの状態。
該当のソースコード
C#
using UnityEngine;
public class GameSystem : MonoBehaviour
{
private bool Flag = false;
public StageSetUp setUp;
public Write prob;
public InputManger ipt;
private int i = 0;
// Start is called before the first frame update void Start() { Debug.Log("G1"); setUp = GameObject.Find("StageSetUp").GetComponent<StageSetUp>(); prob = GameObject.Find("Proglam").GetComponent<Write>(); ipt = GameObject.Find("InputField").GetComponent<InputManger>(); } public void OnGUI() { Debug.Log("G2"); float sizeX = 30; float sizeY = 30; float x = Screen.width / 2 + sizeX * 12; float y = Screen.height / 2 + sizeY * 1; if (GUI.Button(new Rect(x, y + sizeY * 4, sizeX , sizeY),"2")&& Flag == false) { if (i == 8) { } else { setUp.makeStage_1(); prob.Nu_1(); } Flag = true; } if (GUI.Button(new Rect(x, y + sizeY * 5, sizeX, sizeY), "3") && Flag == false) { if (i == 8) { } else { setUp.makeStage_2(); prob.Nu_1(); } Flag = true; i += 1; }
C#
1using UnityEngine; 2using UnityEngine.UI; 3 4public class InputManger : MonoBehaviour 5{ 6 public InputField inputfield; 7 public Text scoreText; 8 public int score = 0; 9 public bool FF; 10 public string star; 11 // Start is called before the first frame update 12 void Start() 13 { 14 Debug.Log("I1"); 15 FF = false; 16 scoreText.text = " "; 17 inputfield = GetComponent<InputField>(); 18 } 19 20 // Update is called once per frame 21 void Update() 22 { 23 Debug.Log(FF); 24 if (FF== true) 25 { 26 inputfield = null; 27 } 28 } 29 public void InputLonger() 30 { 31 Debug.Log("I3"); 32 string inputValue = inputfield.text; 33 string star = inputfield.text; 34 score = int.Parse(inputValue); 35 Text p = GameObject.Find("Text").GetComponent<Text>(); 36 InitInputField(); 37 score =int.Parse("Text"); 38 FF = true; 39 } 40 void InitInputField() 41 { 42 Debug.Log("I4"); 43 scoreText.text = string.Format(inputfield.text); 44 inputfield.text = " "; 45 inputfield.ActivateInputField(); 46 } 47} 48
が試したこと
InputFieldの紐づけがうまく行ってないのかと思い、逆にゲームの始めにキーボードの数字を打ち込んで見ところ、げーむしーんに数字が表示され、InnspecterのScoreにも数字が入りました。
スクリプトの実行順が悪いのかと思ってScript Execution Orderを書き換えてみましたが効果はありませんでした。
補足情報(FW/ツールのバージョンなど)
Unity2018.3

回答1件
あなたの回答
tips
プレビュー