Why is the "Can't convert type int to bool" Error coming up?

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Weapon : MonoBehaviour
{
    public Transform firePoint1;
    public Transform firePoint2;
    public Transform firePoint3;
    public GameObject playerBulletPrefab;
    public int playerShotNum = 0;
    void Start()
    {
     
    }

    void FixedUpdate()
    {
        if (Input.GetMouseButton(0)){
            if (playerShotNum = 2){
                Shoot();
                playerShotNum = 0;
            }else{
                playerShotNum++;
            }
        }
        void Shoot (){
            Instantiate(playerBulletPrefab, firePoint1.position, firePoint1.rotation);
        }
    }
}

And for some reason, it keeps saying that line 22 ( if(playerShotNum = 2) { ) has the “Cannot convert type int to type bool” error. I am using the newest version of unity (V 2021.1.18f1), and no matter what I do, it just keeps popping up. Can someone please help?

Your if statement should be using double equals, which is equality test (takes two values and returns a bool).

You are using a single equal which is assign and return assigned value, which is integer, hence the complaint.

Thank You!

1 Like