Changing behaviors when referencing another script?

I feel like I should know this I’m just drawing a blank.

I have a MonoSingleton script for the items in my game and I’m referencing the item script from another script when the player wants to use the item… but I need it to not give the item if the player has none left

Here is an example of the code I have:

 public void UseGoggles()
    {
        if (Goggles <= 0)
            Debug.LogWarning("None Left!");

        if (Goggles >= 1)
            Goggles -= 1;
            SaveSystem.SaveItems(this);
    }

This is from the item script

 public void GiveGoggles()
    {
        goggles.SetActive(true);
        Items.Instance.UseGoggles();
    }

This is the code referencing the item script… I know there is a simple way to have it not set them as active if the item count is 0… any help is greatly appreciated!

Do you have method in your item script to get the item count?

Yes I do… the item count is displayed above the toggles that the player can check to use the item before they start the level

I am not sure if I understood your problem. Are you looking for something like this.?

Items:

public bool HasGoggles()
{
    return Goggles > 0;
}

Object:

public void GiveGoggles()
{
    goggles.SetActive( Items.Instance.HasGoggles() );
    Items.Instance.UseGoggles();
}

You could also return a bool from UseGoggles() directly and then use this in SetActive().

ok this might work I’ll have to give it a try!

I should have been more clear I apologize… the script referencing the items script is what is called from the “OnValueChange” in the inspector on the toggle… so when the player clicks the toggle it is supposed to give them the item, but the way I have it coded the item is given no matter what the number is.