Issue with if statement in my code

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

else if (number < 26)

This case already covers any number that is less than 12 as well, so your third else if block will never be able to execute. Maybe change it to check for numbers less than 26 but greater than or equal to 12?

Would this work? :

if (number > 26)
        {
            Debug.Log("Number is greater than 26");
        }

        else if (number < 26 && number > 12)
        {
            Debug.Log("Less than 26 but greater than 12");
        }

        else if (number < 12)
        {
            Debug.Log("Less than 12");
        }

Almost, but you’re missing the cases where number is exactly 26 or 12. You should think about which bucket those belong in and change some of the conditions to >= or <= which means “less than or equal to” and “greater than or equal to”.