Is (bool example) true?

Is it possible to know whether the bool example is true from another script and if so how.

public void Active (bool example)
{
}

Thankyou.

You can only know it, if you assign the boolean value from example to an instance or static variable, meaning one that is preserved in the script.

Here is a short example to preserve the variable, that it can be accessed from other scripts:

public class X {
    public bool preservedExample;

    public void Active (bool example) {
        preservedExample = example;
    }
}

There are other ways, like using properties which would allow you to make it read only, by not declaring the setter, or you may just make it available through a method call.

1 Like

Thankyou Greatly Dantus. :slight_smile:

Im having trouble on my second script calling the bool preservedExample. Im obliviously not going about it in the right manner. Could you guide me strait.

public class SecondScript{
      
        public x Active;
      
        public void AreYouActive()
        {
            if (Active.preservedExample == true)
            {
                //Do somthing
            }
          
        }
    }

Thankyou

I would recommend you to read C# naming conventions:
http://www.dofactory.com/reference/csharp-coding-standards

Other than misleading variable and class naming, code should compile correctly I guess. If you’re asking how to improve code visually, you could try:

public class SecondScript : MonoBehaviour
{    
        public FirstScript target;
     
#region Script Lifecycle

        void Start()
        {

        }

        void Update()
        {

        }

        void OnDestroy()
        {

        }

#endregion

#region Functions

        public void PerformAction()
        {
              if ( target == null || !target.preservedExample )
                   return;
             
              // Do something
        }

#endregion

}

Hope it helps!

1 Like

That definitely helps. I will wholeheartedly agree that my naming conventions are terrible so thank you very much for that link Bookmarked.