C#
1#pragma warning disable 0414 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.UI; 6using UnityEngine.SceneManagement; 7 8public class Statistics : MonoBehaviour 9{ 10 public Text targetText; 11 12 public int Level;//レベル 13 public string Ability;//特性 14 public int HP; 15 public int Attack;//こうげき 16 public int Defense;//ぼうぎょ 17 public int Sp_Atk;//とくこう 18 public int Sp_Def;//とくぼう 19 public int Speed;//すばやさ 20 public int Evasion;//回避 21 public int Accuracy;//命中 22 public string Gender;//性別 23 public int Exp;//経験値 24 public int Individual_Value;//個体値 25 public string ATKorSPATK; 26 27 int OK = 0; 28 29 Text SpeciesText; 30 string Text; 31 Image targetImage; 32 33 GameObject targetObj; 34 35 public bool textopen = false; 36 37 // ラジアン変数 38 private float rad; 39 // 現在位置を代入する為の変数 40 private Vector2 Position; 41 42 public Vector2 speed = new Vector2(0.01f, 0.01f); 43 44 bool OK2 = false; 45 46 private void Awake() 47 { 48 SpeciesText = GameObject.Find("SpeciesText").GetComponent<Text>(); 49 Text = "Species:"; 50 SpeciesText.text = Text; 51 targetImage = GameObject.Find("SpeciesImage").GetComponent<Image>(); 52 targetText = GameObject.Find("StatsText").GetComponent<Text>(); 53 Generate_Stats(); 54 targetText.text = ""; 55 } 56 57 private void Update() 58 { 59 if (HP <= 0) 60 { 61 HP = 0; 62 } 63 64 if(OK2 == true) 65 { 66 targetText.text = "Level " + Level.ToString() + "\n" + "Ability " + Ability + "\n" + "Gender " + Gender + "\n" + "IV " + Individual_Value.ToString() + "\n" + 67 "HP " + HP.ToString() + "\n" + "Attack " + Attack.ToString() + "\n" + "Defense " + Defense.ToString() + "\n" + 68 "Sp_Atk " + Sp_Atk.ToString() + "\n" + "Sp_Def " + Sp_Def.ToString() + "\n" + "Speed " + Speed.ToString() + "\n" + 69 "Evasion " + Evasion.ToString() + "\n" + "Accuracy " + Accuracy.ToString() + "\n" + "Exp " + Exp.ToString() + "\n" + "ATK Type " + ATKorSPATK; 70 71 } 72 } 73 74 public void OnClick() 75 { 76 OK2 = true; 77 targetText.text = "Level " + Level.ToString() + "\n" + "Ability " + Ability + "\n" + "Gender " + Gender + "\n" + "IV " + Individual_Value.ToString() + "\n" + 78 "HP " + HP.ToString() + "\n" + "Attack " + Attack.ToString() + "\n" + "Defense " + Defense.ToString() + "\n" + 79 "Sp_Atk " + Sp_Atk.ToString() + "\n" + "Sp_Def " + Sp_Def.ToString() + "\n" + "Speed " + Speed.ToString() + "\n" + 80 "Evasion " + Evasion.ToString() + "\n" + "Accuracy " + Accuracy.ToString() + "\n" + "Exp " + Exp.ToString() + "\n" + "ATK Type " + ATKorSPATK; 81//省略
クリックしたときにUpdateのOKをtrueにして、ステータスがuGUIのText上に更新されるようにしています。
このスクリプトがアタッチされたイベントトリガーを持つオブジェクトを、複数体生成しています。そして、一体一体、別々のステータスの値を持っています。
ですが、OKをtrueにすると、一番最初にクリックしたオブジェクトのステータスがずっと表示されたままで、別のオブジェクトをクリックしても、そのステータスが表示されません。
実現したいことは、クリックしたときに、別々のステータスをText上に表示することです。
ステータスは、一定時間ごとに更新されるので、Updateする必要があります。
ずっと悩んでいたのですが、解決策が思いつきません。
出来れば、実現する方法を教えていただきたいです。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/05/15 19:55