The If Statement can't be read.

Hi there, I have a problem here and I’ve tried many solutions but it did not work. My main program or my whole project works like this. First, the user will pick a room. For instance bedroom. The program will give different furniture or appliances that is on the bedroom. So the first furniture is the bed. There will be a question that will be asked: “What is the size of your bed?” There will be choices, and the choices are buttons. For instance the chosen size is the first button. Once it is clicked it will load to next scene. In the next scene, the program will ask the user how many bed they have. Then after that there will be next question. The next question is “What is the size of your cabinet?” after choosing the size, it will load to the next scene and ask again the user how many cabinet they have. So after getting the size and number of appliance, there will be a script that will give the summarize of their inputs. After that there will be a button that will load to another scene that will display the objects they have inputted. But my script is not working. It works if the first if statement is correct. I think the problem is that the program is not reading the other if statements if the bed is small and the cabinet is medium. Those are the sizes but if the user choose small bed and small cabinet, it displays. What is wrong with my program? Please I really need help. :frowning:

using UnityEngine;
using System.Collections;

public class afinish : MonoBehaviour {
   
    public static string Kama1 = bedA.kamaA;
    public static string Kabinet1 = cabinetA.kabinetA;
    public static string Kama2 = bedB.kamaB;
    public static string Kabinet2 = cabinetB.kabinetB;
    public GUIStyle Display1;
    public GUIStyle Display;
    public GameObject una; //bed
    public GameObject una1; //cabinet
    public GameObject first; //bed
    public GameObject first1; //cabine
    public float guiPlacementX1;
    public float guiPlacementY1;
    public float guiPlacementX2;
    public float guiPlacementY2;
    bool hide = true;
    bool hide1 = true;
   
    void OnGUI(){
        if (hide && GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .2f, Screen.height * .3f), "", Display)) {
                        //Chair
                        hide = false;
                        //small bed
                        if (int.Parse (Kama1) == 1) {
                                GameObject kama1 = Instantiate (una) as GameObject;
                                kama1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kama1.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kama1.transform.Rotate (0f, 88.33871f, 0f);
                                Debug.Log ("gumana ka naman. :(((");
                        }
                        if (int.Parse (Kama1) == 2) {
                                GameObject kama1 = Instantiate (una) as GameObject;
                                kama1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kama1.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kama1.transform.Rotate (0f, 88.33871f, 0f);
               
                                GameObject kama2 = Instantiate (una) as GameObject;
                                kama2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kama2.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kama2.transform.Rotate (0f, 88.33871f, 0f);
                                Debug.Log (" gumana ka naman. :(((");
                        }
                        if (int.Parse (Kama1) == 3) {
                                GameObject kama1 = Instantiate (una) as GameObject;
                                kama1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kama1.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kama1.transform.Rotate (0f, 88.33871f, 0f);
               
                                GameObject kama2 = Instantiate (una) as GameObject;
                                kama2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kama2.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kama2.transform.Rotate (0f, 88.33871f, 0f);
               
                                GameObject kama3 = Instantiate (una) as GameObject;
                                kama3.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kama3.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kama3.transform.Rotate (0f, 88.33871f, 0f);
                                Debug.Log ("gumana ka naman. :(((");
                        }
                        //cabinet
                        if (int.Parse (Kabinet1) == 1) {
                                GameObject kabinet1 = Instantiate (una1) as GameObject;
                                kabinet1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kabinet1.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kabinet1.transform.Rotate (0f, 88.33871f, 0f);
                                Debug.Log ("gumana ka naman. :(((");
                        }
                        if (int.Parse (Kabinet1) == 2) {
                                GameObject kabinet1 = Instantiate (una1) as GameObject;
                                kabinet1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kabinet1.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kabinet1.transform.Rotate (0f, 88.33871f, 0f);
               
                                GameObject kabinet2 = Instantiate (una1) as GameObject;
                                kabinet2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kabinet2.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kabinet2.transform.Rotate (0f, 88.33871f, 0f);
                                Debug.Log ("gumana ka naman. :(((");
                        }
                        if (int.Parse (Kabinet1) == 3) {
                                GameObject kabinet1 = Instantiate (una1) as GameObject;
                                kabinet1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kabinet1.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kabinet1.transform.Rotate (0f, 88.33871f, 0f);
               
                                GameObject kabinet2 = Instantiate (una1) as GameObject;
                                kabinet2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kabinet2.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kabinet2.transform.Rotate (0f, 88.33871f, 0f);
               
                                GameObject kabinet3 = Instantiate (una1) as GameObject;
                                kabinet3.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                                kabinet3.transform.localScale = new Vector3 (100f, 100f, 100f);
                                kabinet3.transform.Rotate (0f, 88.33871f, 0f);
                                Debug.Log (" gumana ka naman. :(((");
                        }
                }
         if (hide1 && GUI.Button (new Rect (Screen.width * guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .2f, Screen.height * .3f), "", Display1)) {
            hide1 = false;
            //bed
            if (int.Parse (Kama2) == 1) {
                GameObject kama1 = Instantiate (first) as GameObject;
                kama1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kama1.transform.localScale = new Vector3 (100f, 100f, 100f);
                kama1.transform.Rotate (0f, 88.33871f, 0f);
                Debug.Log("gumana ka naman. :(((");
            }
            if (int.Parse (Kama2) == 2) {
                GameObject kama1 = Instantiate (first) as GameObject;
                kama1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kama1.transform.localScale = new Vector3 (100f, 100f, 100f);
                kama1.transform.Rotate (0f, 88.33871f, 0f);
               
                GameObject kama2 = Instantiate (first) as GameObject;
                kama2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kama2.transform.localScale = new Vector3 (100f, 100f, 100f);
                kama2.transform.Rotate (0f, 88.33871f, 0f);
                Debug.Log("gumana ka naman. :(((");
            }
            if (int.Parse (Kama2) == 3) {
                GameObject kama1 = Instantiate (first) as GameObject;
                kama1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kama1.transform.localScale = new Vector3 (100f, 100f, 100f);
                kama1.transform.Rotate (0f, 88.33871f, 0f);
               
                GameObject kama2 = Instantiate (first) as GameObject;
                kama2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kama2.transform.localScale = new Vector3 (100f, 100f, 100f);
                kama2.transform.Rotate (0f, 88.33871f, 0f);
               
                GameObject kama3 = Instantiate (first) as GameObject;
                kama3.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kama3.transform.localScale = new Vector3 (100f, 100f, 100f);
                kama3.transform.Rotate (0f, 88.33871f, 0f);
                Debug.Log("gumana ka naman. :(((");
            }
            //cabinet
            if (int.Parse (Kabinet2) == 1) {
                GameObject kabinet1 = Instantiate (first1) as GameObject;
                kabinet1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kabinet1.transform.localScale = new Vector3 (100f, 100f, 100f);
                kabinet1.transform.Rotate (0f, 88.33871f, 0f);
                Debug.Log("gumana ka naman. :(((");
            }
            if (int.Parse (Kabinet2) == 2) {
                GameObject kabinet1 = Instantiate (first1) as GameObject;
                kabinet1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kabinet1.transform.localScale = new Vector3 (100f, 100f, 100f);
                kabinet1.transform.Rotate (0f, 88.33871f, 0f);
               
                GameObject kabinet2 = Instantiate (first1) as GameObject;
                kabinet2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kabinet2.transform.localScale = new Vector3 (100f, 100f, 100f);
                kabinet2.transform.Rotate (0f, 88.33871f, 0f);
                Debug.Log("gumana ka naman. :(((");
            }
            if (int.Parse (Kabinet2) == 3) {
                GameObject kabinet1 = Instantiate (first1) as GameObject;
                kabinet1.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kabinet1.transform.localScale = new Vector3 (100f, 100f, 100f);
                kabinet1.transform.Rotate (0f, 88.33871f, 0f);
               
                GameObject kabinet2 = Instantiate (first1) as GameObject;
                kabinet2.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kabinet2.transform.localScale = new Vector3 (100f, 100f, 100f);
                kabinet2.transform.Rotate (0f, 88.33871f, 0f);
               
                GameObject kabinet3 = Instantiate (first1) as GameObject;
                kabinet3.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
                kabinet3.transform.localScale = new Vector3 (100f, 100f, 100f);
                kabinet3.transform.Rotate (0f, 88.33871f, 0f);
                Debug.Log("gumana ka naman. :(((");
            }
        }
    }
}

I simplified your code a bit… :slight_smile:

using UnityEngine;
using System.Collections;

public class afinish : MonoBehaviour
{
    public static string Kama1 = bedA.kamaA;
    public static string Kabinet1 = cabinetA.kabinetA;
    public static string Kama2 = bedB.kamaB;
    public static string Kabinet2 = cabinetB.kabinetB;
    public GUIStyle Display1;
    public GUIStyle Display;
    public GameObject una; //bed
    public GameObject una1; //cabinet
    public GameObject first; //bed
    public GameObject first1; //cabine
    public float guiPlacementX1;
    public float guiPlacementY1;
    public float guiPlacementX2;
    public float guiPlacementY2;
    bool hide = true;
    bool hide1 = true;
   
    void OnGUI()
    {
        if (hide && GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .2f, Screen.height * .3f), "", Display))
        {
            //Chair
            hide = false;

            //small bed
            if (DoInstantiate (Kama1, una))
                Debug.Log ("gumana ka naman. :(((");

            //cabinet
            if (DoInstantiate (Kabinet1, una1))
                Debug.Log ("gumana ka naman. :(((");
        }

        if (hide1 && GUI.Button (new Rect (Screen.width * guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .2f, Screen.height * .3f), "", Display1))
        {
            hide1 = false;
            //bed
            if (DoInstantiate (Kama2, first))
                Debug.Log ("gumana ka naman. :(((");

            //cabinet
            if (DoInstantiate (Kabinet2, first1))
                Debug.Log ("gumana ka naman. :(((");
        }
    }

    int DoInstantiate (string choice, GameObject what)
    {
        int count = int.Parse (choice);
       
        for (int i = 0; i < count; i++)
        {
            GameObject go = Instantiate (what) as GameObject;
            go.transform.position = new Vector3 (-1.405897f, 1.676556f, 378.3273f);
            go.transform.localScale = new Vector3 (100f, 100f, 100f);
            go.transform.Rotate (0f, 88.33871f, 0f);
        }
       
        return count;
    }
}

All objects get deleted when you load a new scene.
Maybe that’s your problem? o;

Sir. your code has an error. saying cannot implicitly convert type int to bool

maybe? i really dont know what is happening on my code. the first gameobject on my button will work but the second one will not work. when i input at Kama1 then i input again in Kabinet2 the Kama1 will be the one who only works and display the gameobject while Kabinet will not work.

Try to explain better what is happening. We don’t know what are you meaning with “it works” and we don’t know what you expect from this code.

The DoInstanciate method returns an integer and you try to use this as the value for a conditionnal statement.

You need to compare the integer value to another to get a boolean. For example, if(DoInstantiate (Kama2, first) > 0) if you want it to be valid when you did instanciate furnitures :wink:

Thx _met44 :slight_smile: I didn’t notice he was getting an error. Depending on what he need more he can also change the function to return a bool when count > 0.

Absolutely, both are legitimate ways of doing it and should be decided based on actual requirements.