Changing the state of a bool

In my game the player must collect a vaccine before he can move on to the next scene. This C# script is attached to the vaccine game object:

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

public class GetVaccine : MonoBehaviour
{
    public GameObject Vaccine;
    public GameObject VaccineText;
    public bool gotVaccine;

    void OnTriggerEnter(Collider other)
    {
        StartCoroutine(PickVaccine());
    }
    IEnumerator PickVaccine()
    {

        VaccineText.SetActive(true);        // display a text message telling the player he now has the vaccine
        yield return new WaitForSeconds(2); // wait for 2 seconds
        VaccineText.SetActive(false);       // remove the text
        Vaccine.SetActive(false);           // remove the vaccine game object from the scene
    }
}

I then need to record the bool gotVaccine as true but I can't work out how to do that. The bool needs to be available in another script for when the player tries to leave the scene, as a test for whether or not he has the vaccine. Can anybody help please?

Um... Have you triedgotVaccine = true;

PraetorBlue Thank you. I was over-complicating things when the solution turns out to be simple. Can you help me further by telling me how the bool result can be used in another script?


Have the bool public or have a public method to return the value of the bool

Thank you again for your help It works :p