title: How can I assign multiple scripts to public values inside of my main script?
body: <p>I am working on a game on Unity2D with different characters on screen. A big part of the game is switching between these characters to solve puzzles, as different characters can solve certain puzzles. I have a public bool in each script for the different characters which tells the script whether that character is active or not, to determine whether you can control them. My issue occurs when I try to assign the different scripts I need to my main script. I have three different game objects containing scripts I need values from, but I am unsure about how I would be able to do that. The three scripts I need are inside GameObjects in the hierarchy, I am a bit stuck as I can't assign their scripts to my main class.</p>
  <p>Here is the code for my main script incase it helps:</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class MainScript : MonoBehaviour
  {
      public Movement_Leader leaderScript; //The three public values for the scripts
      public Movement_Jumper jumperScript;
      public Movement_Dasher dasherScript;
  
      // Start is called before the first frame update
      void Start()
      {
          leaderScript = GetComponent&lt;Movement_Leader&gt;(); //The values are assigned a null value when the Start() method is called
  
          jumperScript = GetComponent&lt;Movement_Jumper&gt;();
  
          dasherScript = GetComponent&lt;Movement_Dasher&gt;();
      }
  
      // Update is called once per frame
      void Update()
      {
          if (Input.GetButtonDown(&quot;Fire2&quot;))
          {
              ChangeCharacter();
          }
      }
  
      void ChangeCharacter()
      {
          print(leaderScript.leaderActive);
          print(jumperScript.jumperActive);
          print(dasherScript.dasherActive);
          if (leaderScript.leaderActive == true)
          {
              leaderScript.leaderActive = false;
              jumperScript.jumperActive = true;
  
          }
          else if (jumperScript.jumperActive == true)
          {
              jumperScript.jumperActive = false;
              dasherScript.dasherActive = true;
          }
          else if (dasherScript.dasherActive == true)
          {
              leaderScript.leaderActive = true;
              dasherScript.dasherActive = false;
          }
      }
  }
  </code></pre>