# Compare Contents of arrays

 0 Alright the problem here is i want my array to be a int[]. The problem is I do not know how to compare one number to all the contents of a array. Here is my code: ``````var randomNum : int; var randomNum2 : int; var compareNumber : int[]; var constantNum : int = 0; var once : boolean = true; var brick : Transform; var rowOne : Transform[]; var rowTwo : Transform[]; function Start () { } function Update () { if (once) { randomNum = Random.Range(1,5); if (randomNum > 0) { if(randomNum2 == compareNumber) { randomNum2 = Random.Range(1,rowOne.length); compareNumber[constantNum] = randomNum2; Instantiate(brick, rowOne[randomNum2].transform.position, Quaternion.identity); constantNum++; } else { randomNum2 = Random.Range(1,rowOne.length); } randomNum--; } once = false; } } `````` The problem is the line: if(randomNum2 == compareNumber) {...well i KNOW it is wrong, thus the problem. What i want is IF the 2nd random number IS in the array it picks a new random number. The correct syntax (at least what i want) is: ``````if(randomNum2 !== compareNumber) { `````` The problem is that compareNumber is a int[] so i can not see if it not equal to it, or so unity says. So how do i got about having it compare to the contents of the array? Sorry for this sort of question, i am new to arrays and i want to start using them because they are just so useful, just complex i guess. more ▼ asked Jun 08 '10 at 09:52 PM xToxicInferno 485 ● 24 ● 28 ● 41 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 So something like ``````if( System.Array.IndexOf( compareNumber, randomNum2 ) == -1 ) { // it doesn't exist in the array } `````` more ▼ answered Jun 08 '10 at 10:16 PM Tetrad 7.2k ● 27 ● 37 ● 89 I get a error saying that IndexOf is not a member of Array. Jun 08 '10 at 10:20 PM xToxicInferno Use System.Array.IndexOf so it doesn't mix it up with UnityEngine.Array Jun 08 '10 at 10:29 PM Mike 3 Edited my post so it should compile as is Jun 13 '10 at 10:28 AM Tetrad add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1363
x355
x52

asked: Jun 08 '10 at 09:52 PM

Seen: 2303 times

Last Updated: Jun 08 '10 at 09:52 PM