samedi 28 janvier 2017

Bool not returning true in IF statement C# Unity

GameObject ZombieCard1, ZombieCard2, ZombieCard3, ZombieCard4, ZombieCard5;
int randomnumberpicker;
public static bool leftChoice, rightChoice;
void Start()
{

    statusBars = FindObjectOfType<StatusBars>();
}


void Update()
{
    ZombieCards();

}

void ZombieCards()
{
    if (GameObject.FindWithTag("Card") == null)
    { 
     randomnumberpicker = Random.Range(1, 5);
     Debug.Log(randomnumberpicker);
     if(randomnumberpicker == 1)
        {
           ZombieCard1 = Instantiate(Resources.Load("Frontcard1")) as GameObject;
           ZombieCard1.transform.Translate(0, -1, 0);
            if (leftChoice == true)
            {
                Debug.Log("Jesus Marty! you fixed it! Great Scott!");
            }
        }
     else if(randomnumberpicker == 2)
        {
            ZombieCard2 = Instantiate(Resources.Load("Frontcard2")) as GameObject;
            ZombieCard2.transform.Translate(0, -1, 0);
        }
     else if (randomnumberpicker == 3)
        {
            ZombieCard3 = Instantiate(Resources.Load("Frontcard3")) as GameObject;
            ZombieCard3.transform.Translate(0, -1, 0);
        }
     else if (randomnumberpicker == 4)
        {
            ZombieCard4 = Instantiate(Resources.Load("Frontcard4")) as GameObject;
            ZombieCard4.transform.Translate(0, -1, 0);
        }
     else if (randomnumberpicker == 5)
        {
            ZombieCard5 = Instantiate(Resources.Load("Frontcard5")) as GameObject;
            ZombieCard5.transform.Translate(0, -1, 0);
        }
    }
}
 void OnMouseDown()
    {
        if (gameObject.CompareTag("LeftArrow"))
        {
            leftChoice = true;
            Debug.Log("Left arrow is working");
            return;
        }
        if (gameObject.CompareTag("RightArrow"))
        {
            rightChoice = true;
            Debug.Log("Right arrow is working");
            return;
        }
    }
}

I posted this earlier but due to lack of clarity (on my part) I can't figure out why this if statement

if (leftChoice == true)
        {
            Debug.Log("Jesus Marty! you fixed it! Great Scott!");
        }

isn't executing, the bool is being set to true on mousedown correct?

Any help would be greatly appreciated

Aucun commentaire:

Enregistrer un commentaire