Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question how to check a bool from another script

Discussion in 'Scripting' started by Fuocartex, Dec 28, 2020.

  1. Fuocartex

    Fuocartex

    Joined:
    Jun 2, 2020
    Posts:
    13
    I have two script in the firs i have a public bool Pippo.
    in the second script I want to do something if pippo is true. How i can do that if I use getcomponent it doesn't work
     
    Last edited: Dec 28, 2020
  2. Fuocartex

    Fuocartex

    Joined:
    Jun 2, 2020
    Posts:
    13
    this is the first script
    Code (CSharp):
    1. public class PlatformerCharacter2D : MonoBehaviour
    2.     {
    3.                public bool m_FacingRight = true;  
    4.  
    this is the second
    Code (CSharp):
    1. namespace GameAssets._2D
    2. {
    3.  
    4.    
    5.     public class ArmRotation : MonoBehaviour
    6.     {
    7.         public int rotationOffset;
    8.         public float rotz;
    9.         public float MinRot;
    10.         public float MaxRot;
    11.  
    12.         private PlatformerCharacter2D m_Character;
    13.  
    14.         // Start is called before the first frame update
    15.         void Start()
    16.         {
    17.  
    18.             m_Character = GetComponent<PlatformerCharacter2D>();
    19.         }
    20.  
    21.         // Update is called once per frame
    22.         void Update()
    23.         {
    24.             rotation();
    25.             if (rotz>=MinRot && rotz<=MaxRot)
    26.             {
    27.                 transform.rotation = Quaternion.Euler(0f, 0f, rotz + rotationOffset);
    28.             }
    29.  
    30.             if(m_Character.m_FacingRight)
    31.             {
    32.                 Dbug.LorWarning("some");
    33. <            }
    34.  
    35.             //need to lock the rotation and reverse the arm when he walk left
    36.         }