错误CS0029:无法隐式转换类型`int' to bool' - Unity3D

时间:2015-01-29 16:40:42

标签: c# unity3d int boolean

我收到错误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);


}
}

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

2 个答案:

答案 0 :(得分:1)

您正在使用分配运算符

(checked = true) 

不一样
(checked == true) 

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

答案 1 :(得分:0)

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

PlayerPrefs.GetFloat返回一个浮点数。您不能将float用作if语句中的条件。

您正在寻找类似

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

您还要分配点击而不是评估您在某些if语句中点击的内容。这将导致比未能编译更微妙的错误。但是,您的编辑与上述内容有关。