Unityで,monobehaviourを継承しないクラスを作成し下記のようなスクリプトを作成しました。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Const; 5 6public class HogeManage { 7 Dictionary<string, int> dic = new Dictionary<string, int>() { 8 {"hoge1", 0}, 9 {"hoge2", 0), 10 {"hoge3", 0}, 11 }; 12 13 //valueが0が1つでもあればvalueをupdateして返す 14 public bool GetZeroHoge() 15 { 16 foreach (KeyValuePair<string, int> pair in dic) 17 { 18 Debug.Log(pair.Key); 19 if (pair.Value == 0) 20 { 21 dic[key] = 1; 22 return true; 23 } 24 } 25 return false; 26 } 27}
これを別Scriptのupdateで
C#
1var hogeManage = new HogeManage(); 2hogeManage.GetZeroHoge();
GetZeroHogeを呼び出しています。
が、次にGetZeroHogeが呼ばれた時に、dic[key] = 1;が聞いていません。
このscript内の関数で dic
を使いまわすことはできないでしょうか、、、??
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/18 10:42