Hi, This is fourth video on “How to code in unity with C#” series. I will explain you how to use if condition works in c# and how to use it in unity.
Code:
public class TutorialFour : MonoBehaviour
{
public int x;
public int y;
public bool truthOrNot;
// Start is called before the first frame update
void Start()
{
Compare();
}
public void Compare() //x>y; < ; >= ; <= ; == ; !=
{
if (x > y)
{
Debug.Log("X is bigger than Y");
}
else if(x < y)
{
Debug.Log("X is smaller than Y");
}
else
{
Debug.Log("X and Y are equal");
}
if (truthOrNot)
{
Debug.Log("Sentence is true");
}
if (truthOrNot && x > y) // or ||
{
Debug.Log("Sentence is true and X is bigger than Y");
}
}
}