Script A
I have 2 public string
public string[] Word;
public string[] Color;
There have been added following string, though the Inspector
• Black, Blue, Brown, Green, Orange, Pink, Purple, Red, White, Yellow
In that order and in both of the strings.
Script B
When OnMouseDown action, it gonna send a string Array to Script A, this array is 2 long.
f.x it could contain → Green, Yellow
Script A
I have this code in Script A
void BoxClicked(string[] boxInfo)
{
// For Loops Doesn't work properly
for (int i = 0; i<Word.Length; i++) {
Debug.Log(i+" Word in array: "+Word[i]+" Color in Array: "+Color[i]);
if(string.Compare(boxInfo[0],Word[i]) == 1)
ClickedWord = i;
if(string.Compare(boxInfo[1],Color[i]) == 1)
ClickedColor = i;
}
Debug.Log ("Clicked Word: " + boxInfo [0] + " (" + ClickedWord + ") ("+Word[ClickedWord]+") Clicked Color: " + boxInfo [1] + " (" + ClickedColor + ") ("+Color[ClickedColor]+")");
}
What the script is gonna do is to compare the boxInfo string with Word[ ] and Color[ ]
So when the input parameter to boxInfo is Green, Yellow
We gotta count on that ClickedWord = 3, and ClickedColor = 9
But it doesn’t give me that out.
Here is the Debug.Log test:
0 Word in array: Black Color in Array: Black
1 Word in array: Blue Color in Array: Blue
2 Word in array: Brown Color in Array: Brown
3 Word in array: Green Color in Array: Green
4 Word in array: Orange Color in Array: Orange
5 Word in array: Pink Color in Array: Pink
6 Word in array: Purple Color in Array: Purple
7 Word in array: Red Color in Array: Red
8 Word in array: White Color in Array: White
9 Word in array: Yellow Color in Array: Yellow
Clicked Word: Green (2) (Brown) Clicked Color: Yellow (8) (White)
I really dont that it doesn’t come out as
Clicked Word: Green (2) (Green) Clicked Color: Yellow (8) (Yellow)
Could you help me sorter it out?