1

I got error CS0029: Cannot implicitly convert type int to bool error.

Here's my code :

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);


}
}

It's simple code but I am still getting error. I tried the commented code too but not succeeded at solving problem. Any help.

1
  • 2
    You should be using == for comparison in if statement, instead of single = Commented Jan 29, 2015 at 16:42

2 Answers 2

2

You're using the assignment operator

(checked = true) 

Which is not the same as

(checked == true) 

The first sets the value of checked to true, the second checks if the variable checked is set to true

Sign up to request clarification or add additional context in comments.

Comments

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

PlayerPrefs.GetFloat returns a float. You can't use a float as the condition in an if statement.

You're looking to do something like

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

You're also assigning to clicked rather than evaluating clicked in some of your if statements. That'll cause a more subtle bug than failing to compile. Your compilation however, is related to the above.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.