アプリで作りたい表(2列目がInputField、3列目がSetActiveでレ点を表示)
上記のような表を1行ずつPrefabで作成しました。
1列目は1から順番に数値が入っています。
(質問)
2列目はInputFieldに入った値を取得
3列目はレ点が入っている場合、2列目の値を倍にして4列目に反映させる
というのを作りたいのですがPrefabでやるとうまくまとまりません。
やってみたこと)
各PrefabのInputFieldでの取得→OK
各Prefabの行にあたるIndexNoの取得→OK
レ点を消したりするSetActive→OK
上記3つをどうすれば4列目の数値に返せるのか?
4列目の値を収納する変数をどちらのスクリプトで宣言すれば良いのか?
がしっくりしません。
分かる方教えて下さい。
環境)
PC: mac
Unity2018.2
言語:C#
InputScript.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; public class InputScript : MonoBehaviour { #pragma warning disable 649 //Inputfieldにテキストを設定する場合はInputfield型にしなければいけない。 [SerializeField]InputField inputText; public string indexNo; //index番号 private int checkFlag; // Start is called before the first frame update void Start() { checkFlag = PlayerPrefs.GetInt("checkflag",0); } public void ValueChangedDistance(string text) { //★indexNoとInputFieldデータを取得 inputText.text = (Convert.ToDouble(text)).ToString("F1"); Debug.Log("indexno:" + this.indexNo); } //Checkをセット public void PushCheck(GameObject checkObject) { if(checkFlag == 0) { checkObject.SetActive(true); PlayePrefs.SetInt("checkflag", 1); } else { checkObject.SetActive(false); PlayePrefs.SetInt("checkflag", 0); } PlayePrefs.Save(); } }
ScrollController.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ScrollController : MonoBehaviour { #pragma warning disable 649 [SerializeField]GameObject listPrefab; private Text[] texts; // Start is called before the first frame update void Start() { for(int i = 0; i < 16; i++) { var item = GameObject.Instantiate(listPrefab) as GameObject; item.transform.SetParent(transform.transform, false); item.GetComponentInChildren<InputScript>().indexNo = i.ToString(); texts = item.GetComponentsInChildren<Text>(); texts[0].text = (i + 1).ToString(); } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/11 07:05