How Do you Have a String in a If statement comparing a bool?

Here is my code

    `void OnCollisionEnter2D (Collision2D collision) {
	howManyHits = howManyHits + 1;
	Destroy (gameObject);
	if (howManyHits = 12) {
		Application.LoadLevel ("YOU WON!");
	}
}`

I want to Use Application.LoadLevel to load the next level when the certain amount of hits is reached, but the bool wont work with the string. Can anyone help me?

You need to use == rather than = in your if statement.

if (howManyHits == 12) {
    Application.LoadLevel ("YOU WON!");
}

= is used for setting variables, == returns boolean true if the left and right sides are identical.

Not that it’s causing a problem, but for convenience’s sake, you can use howManyHits += 1;
It does the same thing as howManyHits = howManyHits + 1; but is slightly quicker to type :stuck_out_tongue:

Thank You! I cant believe I missed that!
Thanks again!