Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Problem with foreach loop
Post Body

I am making roulette game. After number is generated, I am using foreach loop to loop through an array to see if generated number is one of black colors, if it is, it should assign black color to field, but if it is not it should be red. For some reason it doesn't work properly but I don't know why.

Here is code:

public void Spin()

`{`

    `spinNumber = Random.Range(0, 37);`

    `foreach(int i in blackNumbers)`

    `{`

        `if(spinNumber == 0)`

        `{`

spinNumberColor = Color.green;

break;

        `}`

        `else if(spinNumber == i)`

        `{`

spinNumberColor = Color.black;

break;

        `}`

        `else`

        `{`

spinNumberColor = Color.red;

break;

        `}`

    `}`

    `spinNumberText.text = spinNumber.ToString();`

    `spinNumberPanel.color = spinNumberColor;`

`}`

Author
Account Strength
80%
Account Age
10 years
Verified Email
Yes
Verified Flair
No
Total Karma
93
Link Karma
14
Comment Karma
25
Profile updated: 1 day ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago