Search Unity

Reference public bool from one script to another

Discussion in 'Scripting' started by petizero, Sep 23, 2019.

  1. petizero

    petizero

    Joined:
    Jan 1, 2019
    Posts:
    47
    Hi
    what i have is a script that makes a bool true
    what i would like to achive is another script to check if its true before it does anything. Any help?
     
  2. Tiernan98

    Tiernan98

    Joined:
    Jul 11, 2017
    Posts:
    42
    If the script is on the same game object, then you can use the GetComponent method.

    If the script is on another game object, you'll need to create a public or serialized private member variable in the calling script that you can drag the other script into in the editor.

    Only use the game object Find method if you are doing it in Start or Awake, as it is slow.