Why does unity want to convert my int to bool?

I am programming a game that should remove a wall when 12 objects are collected. However, Unity gives me this error message:
Assets/Scripts/RemoveWall.cs(16,17): error CS0029: Cannot implicitly convert type int' to bool’.
Here is the code and the script that is referred to:


using UnityEngine;
using System.Collections;

public class RemoveWall : MonoBehaviour {

	public GameObject removewall1;
	public PlayerController playercontroller;

	void Start()
	{
		PlayerController count = GetComponent<PlayerController> ();
	}

	void Update () 
	{
		if (playercontroller.count = 12)
		{
			GameObject removewall1 = GameObject.FindWithTag ("RemoveWall1");
			if (removewall1 != null) Destroy(removewall1);
		}
	}
}

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerController : MonoBehaviour {


	public float speed;
	public Text countText;
	public Text winText;

	private Rigidbody rb;
	private int countact;
	public int count;


	void Start ()
	{
		rb = GetComponent<Rigidbody>();
		count = 0;
		countact = 0;
		SetCountText ();
		winText.text = "";
	}

	void FixedUpdate ()
	{
		float moveHorizontal = Input.GetAxis ("Horizontal");
		float moveVertical = Input.GetAxis ("Vertical");

		Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

		rb.AddForce (movement * speed);

		if (count >= 12) 
		{
			if(count >= 24)
			{
				if(count >= 36)
				{
					if(count >= 48)
					{
						if(count >= 60)
						{
							if(count >= 72)
							{
								if(count >= 84)
								{
									if(count >= 96)
									{
										if(count >= 108)
										{
											if(count >= 120)
											{
												if(count >= 132)
												{
													if(count >= 144)
													{
														if(count >= 156)
														{
															countact = count - 156;
														}
														countact = count - 144;
													}
													countact = count - 132;
												}
												countact = count - 120;
											}
											countact = count - 108;
										}
										countact = count - 96;
									}
									countact = count - 84;
								}
								countact = count - 72;
							}
							countact = count - 60;
						}
						countact = count - 48;
					}
					countact = count - 36;
				}
				countact = count - 24;
			}
			countact = count - 12;
		}
		else
		{
			countact = count;
		}
	}

	void OnTriggerEnter(Collider other) 
	{
		if (other.gameObject.CompareTag ("Pick Up"))
		{
			other.gameObject.SetActive (false);
			count = count + 1;
			SetCountText ();
		}
	}

	void SetCountText ()
	{
		countText.text = "Count: " + countact.ToString ();

		if (count >= 168)
		{
			winText.text = "You Win!";
		}
	}
}

I would appreciate any help. Thank you!

The if statement on line 16 of the first script MUST have two equals (==) to work.

Line 16 in the first script:

if (playercontroller.count = 12)

This is assigning 12 to .count (which you can’t do anyway because count would be readonly). But since you’re doing an assignment, the result of the expression is an int. And since the expression is part of an if statement, the compiler tries to convert it to a Boolean, and an int can’t be implicitly cast to a bool.

The comparison operator is ==.

So you want:

if (playercontroller.count == 12)

Hey,
I am not sure if this’ll do the trick but on line 16 you wrote this :
if (playercontroller.count = 12)
{
GameObject removewall1 = GameObject.FindWithTag (“RemoveWall1”);
if (removewall1 != null) Destroy(removewall1);
}

however if you want to use the if statement you need to use == instead of =

so I guess you need to write this :
if (playercontroller.count == 12)
{
GameObject removewall1 = GameObject.FindWithTag (“RemoveWall1”);
if (removewall1 != null) Destroy(removewall1);
}

if you don’t use double equal signs its assuming you are you are trying to fill in that value instead of comparing it.