activating and deactivating button with if-then statement

So I made the roll-a-ball game with the unity tut. and I made some modifications such as more levels and a mainmenu and other stuff. After a roll-a-ball game has been completed(if you have seen the tut. you will understand better) by picking up all of the little cubes(In my case 18) with the ball, the words “you win” or (something along those lines) will pop up. Now scince I have multiple levels I decided to put each level on it’s own seperate scene. I also decided to go between those scenes by using buttons. I made a script to deactivate a button when you first start that level and also to activate it when your “count” has reached 18.
I know that my script is working(somewhat) because the button is deactivated when I start my “level”. My problem is that it won’t reactivate when my count reaches 18. Is this because my Button won’t be visible when you move the camera or is it because of my script?? No matter the reason, can somebody help me with this? Please feel free to ask questions, I will try to refresh this page alot and read your responses! This question is on the same project as the one we had a different problem on(if that makes sense) so I will add your names in here to see if you can help me again… @Brogan89 @TheDJBuntin

(The Name of the script is ContinueBtnController and the name of the button is continueBtn) so you don’t get confused.

Here is my !!!C# script!!! :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ContinueBtnController : MonoBehaviour
{

public GameObject continueBtn;

private Text countText;
private int count;
private Text winText;

void Start()
{
    {
        count = 0;
    }
}

**void FixedUpdate()
{
    if (count >= 18)
    {
        continueBtn.SetActive(true);
    }
    else
    {
    continueBtn.SetActive(false)
    }
}**

void SetCountText()
{
    countText.text = "Count: " + count.ToString();
    if (count >= 18)
        winText.text = "You've won!";
}

}

So everything but the if then Statement(stuff that has double * around it is part of the if then statement) is just there so the if then statement can reference the things I wrote in it.

Here is the beginning of a game with the button and “you win” because I haven’t reached 18 yet or started.

I do also have a main script that actually makes the other buttons, moving the player, and texts, work, I just started a new script so I wouldn’t have to deal with all of that when I was just using it for a button.

I can’t see where your count is being updated. There should be somewhere count += 1?

The script is on the button right? So do this:

Make the “count” variable in the MainScript to be public.

Now in the button script declare a reference to the type MainScript;

public MainScript mainScriptRef;

Now in the inspector for the Button drag the object that has the MainScript into the field you created for the button.

The button Code should now read:

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class ContinueBtnController : MonoBehaviour
 {
 
     public GameObject continueBtn;

      public MainScript mainScriptReference;
      
     private Text countText;
     private Text winText;
 
     void FixedUpdate()
     {
         if (mainScriptReference.count >= 18)
         {
             continueBtn.SetActive(true);
         }
         else
         {
             continueBtn.SetActive(false);
         }
     }

     void SetCountText()
     {
         countText.text = "Count: " + mainScriptReference.count.ToString();
         if (mainScriptReference.count >= 18)
             winText.text = "You've won!";
     }
 }

I believe your main problem is that you aren’t realizing that count in one script is not the same variable as count in another script. ANd then you tried to fix it by having this script also “pick up” objects but your buttonController is not involved in the collisions so nothing is going to happen.