- Home /
For values in array
Hello, While making my script i ran into a problem. i need to check for the array values 0,1,2. Like this
if(mountainsTF == true && (x - mountainX[])){
Where mountainX is assigned a mountainX[0],mountainX[1],mountainX[2] values.
I would like to somthing like this,
x-mountainX[0-2]
but i dont think i cando that...
sorry im still learning Unityscipt(Javascript) and im sure theres an easy way to do this...
Answer by Bunny83 · Mar 05, 2013 at 11:39 PM
Sure, just use a for loop:
//UnityScript
//[...]
var anyTrue = false;
for (var i = 0; i < mountainX.Length; i++)
{
if (x - mountainX[i])
{
anyTrue = true;
break;
}
}
if(mountainsTF == true && anyTrue)
{
// [...]
}
//[...]
Answer by highpockets · Mar 05, 2013 at 11:13 PM
You can use the or operator '||' like this:
if(mountainsTF == true && (x - mountainX[0]) || (x - mountainX[1]) || (x - mountainX[2])){
i knew about that but i was wondering if there was another way...
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Why does it give me this error and how can i fix it? 1 Answer
Inventory Help. 2 Answers
Pause Button Help 2 Answers
Multi-Touch help 1 Answer