実現したいこと
GameObjectとそれから取得する値からなるdictionaryを、取得する値でソートしたいです。
取得する値、GameObjectは毎フレーム変化します。
作っているもの
fpsゲームで最も画面中央にあるobject3つのみ選択アイコンが出るようにするプログラムを作っています。画面内にあるGameObjectと中央からの距離のdictionaryは作れたのですが、エラーが出ます。
該当のソースコード
countは画面内にあるGameObjectの数、
lenFromCenterは中央からの距離(float型)、
objListには画面内にあるGameObjectが入っています。
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System.Linq; 5using System; 6 7 int count= 0; 8 List<GameObject> objList= new List<GameObject>(); 9 Dictionary<int, float> dict = new Dictionary<int, float>(); 10 // Use this for initialization 11 void Start () { 12 13 } 14 // Update is called once per frame 15 void Update () { 16 17 if (count > 0) { 18 dict.Clear (); 19 for(int i=0;i<count;i++){ 20 dict.Add (i,objList [i].GetComponent<EventTag> ().lenFromCenter); 21 } 22 var sortdic = dict.OrderBy ((x) => x.Value);//ここでエラーが出ます。 23 } 24 }
エラーメッセージ
Type System.Linq.IOrderedEnumerable<System.Collections.Generic.KeyValuePair<int,float>>' does not contain a definition for
Keys' and no extension method Keys' of type
System.Linq.IOrderedEnumerable<System.Collections.Generic.KeyValuePair<int,float>>' could be found. Are you missing an assembly reference?
回答1件
あなたの回答
tips
プレビュー