Hi there,
I’m a beginner to Unity and C# and I have a question about if statements that I hope someone could help me with?
In the scene of my Unity project I have a quad game object which has a script called “Player.cs” attached to it. In the Player class within the script I have a public integer variable called “number” that has a value of 33.
I have an if statement within the Update method which outputs a message to the console if the “number” variable changes to a certain value.
I can alter the “number” variable in the inspector when I run the project in order to get a particular message in the if statement to pop up in the console.
However the if statement seems to stop working past the part where it checks whether the “number” variable is less than 26. I’m not sure why this is?
Here’s my code below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public int number = 33;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (number > 26)
{
Debug.Log("Number is greater than 26");
}
else if (number < 26)
{
Debug.Log("Less than 26");
}
else if (number < 12)
{
Debug.Log("Less than 12");
}
}
}
I’ve uploaded a video on Youtube here that can better show the issue I am having:
Any helpful information would be appreciated!
Kind regards