2017-08-09 2 views
0

私はいくつかの領域を含むマップを持っています リージョンを選択して色付けしました。私がやりたい すべては、私は最近、フェードインと1を着色する選択している別の領域を選択したときに、私はこれは、2つのインデックスを追加します。地域SpriteRenderer.Color && Colider Interact

targetIndex = System.Array.IndexOf(Maps, target); 
Maps[targetIndex].GetComponent<SpriteRenderer>().color = Color.gray; 
+0

あなたは地域の色が別の選択した色にグレーからlerpしたいと言っていますか? – oxrock

答えて

0

を着色するためのコードである を選択しています。それらをcurrentlySelectedIndexpreviouslySelectedIndexと呼ぶことができます。

以前に選択された領域がないため、これらの2つは最初のオブジェクトを指しています。

2回目以降の選択を行うと、currentlySelectedIndexは新たに選択された領域にアサインされますが、previouslySelectedIndexは引き続き古い領域を指します。

この時点で、領域を塗りつぶしたときのようにpreviouslySelectedIndexを使用します。古い領域の塗りつぶしが完了したら、previouslySelectedIndexcurrentlySelectedIndexと割り当てます。そしてこれは続くでしょう。

擬似

//Check if its the first time Selection 

currentlySelectedIndex = System.Array.IndexOf(Maps, target); 
Maps[currentlySelectedIndex].GetComponent<SpriteRenderer>().color = Color.gray; 
previouslySelectedIndex = currentlySelectedIndex; 

//After the first time selection 

currentlySelectedIndex = System.Array.IndexOf(Maps, target); //New Selected Region 
Maps[currentlySelectedIndex].GetComponent<SpriteRenderer>().color = Color.gray; 
Maps[previouslySelectedIndex].GetComponent<SpriteRenderer>().color = FadeColor; //Old Selected Region 
previouslySelectedIndex = currentlySelectedIndex; 
関連する問題