check bool across a script
so I have this Script: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class e_key_1 : MonoBehaviour { public GameObject get; private GameObject key1; public bool door1;
void OnTriggerEnter()
{
get.SetActive(true);
}
void OnTriggerExit()
{
get.SetActive(false);
}
void OnTriggerStay()
{
if (Input.GetButtonDown("use"))
{
get.SetActive(false);
door1 = true;
}
}
}
And i want to check if the door1 boll is true in a another script...
Btw im german so sorry if some words are wrong
Answer by highpockets · Feb 13, 2021 at 04:34 PM
Well you have to get a reference to that script from the other script:
public class OtherScript : MonoBehaviour
{
[SerializeField] private e_key_1 scriptWithBool;
private void Update()
{
if(scriptWithBool.door1)
{
//it’s true!!!
}
else
{
//it’s false
}
}
}
Your answer
Follow this Question
Related Questions
Why is my bool being set to true when program is run? 1 Answer
My Bool function is returning False but it should be true in my opinion. Csharp C# 0 Answers
Why does Bool code never work in my C# Script? 1 Answer
How to change the Bool for only a single prefab GameObject creating with Instantiate? 2 Answers