- Home /
Question by
Orange-Pixell · Apr 19, 2020 at 06:44 AM ·
if-statementsboolmethodmethodsbooleans
Entering false statement even it is at true state.
I have a bool. And created a method to use in a button. When I click the button it always runs the true statement. Here is the code. I tried writing false statement first.
public void BigBall()
{
if (bigBall)
{
physic.transform.localScale = new Vector3(1f, 1f, 1f);
bigBall = false;
Debug.Log("Big Ball is False");
}
else if (!bigBall)
{
physic.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
bigBall = true;
Debug.Log("Big Ball is True");
}
}
Also I need to keep track of "bigBall" bool because I am going to use it.
Comment
Best Answer
Answer by Orange-Pixell · Apr 19, 2020 at 09:18 AM
It appears the function wasn't returning bool value, that was the problem. So rookie mistake. Ok here is how I solved this., there might be a better solution but this works: I created 2 Vector3 values then use them for the method I use for the button. Then created a bool method for the bool return. And just call the bool method from start. Thats it.
Vector3 bigBallV3 = new Vector3(1.5f, 1.5f, 1.5f);
Vector3 bigBallnormal = new Vector3(1f, 1f, 1f);
public void BigBall()
{
if (physic.transform.localScale == bigBallnormal)
{
physic.transform.localScale = bigBallV3;
bigBall = true;
}
else
{
physic.transform.localScale = bigBallnormal;
bigBall = false;
}
}
public bool CheckBigBall()
{
if (physic.transform.localScale == bigBallnormal)
{
bigBall = false;
}
else
{
bigBall = true;
}
return bigBall;
}