错误 CS0029:无法将类型“int”隐式转换为“bool” - Unity3D

error CS0029: Cannot implicitly convert type `int' to `bool' - Unity3D

我收到错误 CS0029: Cannot implicitly convert type int to bool error

这是我的代码:

using UnityEngine;
using System.Collections;

public class card2 : MonoBehaviour {

public GUISkin MenuSkin;

public int cardinpuani;
public float sekiz = 8;
public float sifir = 0;
public int onalti = 16;
public int dort = 4;
public int yirmi =20;
public int oniki = 12;
public int yirmidort = 24;
public int yirmisekiz = 28;
public bool clicked = false;

void Start () {

}

void Update () {
}

void OnGUI () {

    GUI.skin = MenuSkin;

    if(GUI.Button ( new Rect (0,Screen.height-50,100,50), "No")){
        Application.LoadLevel(4);
    }
    else if(GUI.Button ( new Rect (Screen.width-100,Screen.height-50,100,50), "Yes")){
    clicked = true;
    }
    else if(clicked=true){
        if(sifir = PlayerPrefs.GetFloat("tahmin", sifir)){
            PlayerPrefs.SetFloat("tahmin", sekiz);
            Application.LoadLevel(4);
        }
    }


    /*if(sifir = PlayerPrefs.GetInt("tahmin")){
        PlayerPrefs.SetInt("tahmin", sekiz);
        if(3>1){
        Application.LoadLevel(4);
        }}

        else if(dort = PlayerPrefs.GetInt("tahmin")){
        PlayerPrefs.SetInt("tahmin", oniki);
        Application.LoadLevel(4);
        }
        else if(onalti = PlayerPrefs.GetInt("tahmin")){
        PlayerPrefs.SetInt("tahmin", yirmidort);
        Application.LoadLevel(4);
        }
        else if(yirmi = PlayerPrefs.GetInt("tahmin")){
            PlayerPrefs.SetInt("tahmin", yirmisekiz);
            Application.LoadLevel(4);
        }*/

        //PlayerPrefs.SetInt("tahmin", sekiz);

        //Application.LoadLevel(4);


}
}

这是简单的代码,但我仍然遇到错误。我也尝试了注释代码,但没有成功解决问题。任何帮助。

您正在使用赋值运算符

(checked = true) 

这与

不同
(checked == true) 

第一个设置checked的值为true,第二个检查变量checked是否设置为true

sifir = PlayerPrefs.GetFloat("tahmin", sifir)

PlayerPrefs.GetFloat returns 一个浮动。不能在 if 语句中使用浮点数作为条件。

您想要做的事情类似于

sifir = PlayerPrefs.GetFloat("tahmin", sifir)
if(sifir != 0)
{ 
     PlayerPrefs.SetFloat("tahmin", sekiz);
     Application.LoadLevel(4); 
}

您还在某些 if 语句中分配给 clicked 而不是评估 clicked 。这将导致比编译失败更微妙的错误。但是,您的编译与上述内容有关。