Scripts

Hi, can I assign a bool from a script and check if its true in another? if so how can I do this. I did this but its not working and it always no matter what I try it pops this error :

nullreferenceexception object reference not set to an instance of an object

Here is the script :

private Hands shot;
private Animator MyAnimator;
 public bool Dead;
void Start()
    {
        shot = GetComponent<Hands>();
 MyAnimator = GetComponent<Animator>();
}

void Update()
    {



 MyAnimator.SetBool("Dead", Dead);
}

public void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player" && shot.Shot == true)
        {
            Dead = true;
        }
    }

If the Bool you want to check is in another script, just get the reference to that script. Set up a private variable with the name of the other script and name it something appropriate. Then, get the component in Start like you do with the animator and shot components you used. Then, you can call it with the variableName.BoolToGet = False/True.

Also, do you have a “Dead” bool in your animator parameters?

1 Like

Yes I have