If I have the player walk into something that is a trigger with a certain tag, how can I set a boolean to true and check that it’s true with a script attached to a different object?
public class Player : MonoBehaviour
{
public bool EnteredTrigger;
public void OnTriggerEnter(Collider other)
{
if (other.tag == /*the tag*/)
EnteredTrigger = true;
}
}
public class OtherScript : MonoBehaviour
{
private GameObject m_Player;
private void Start()
{
m_Player = GameObject.FindWithTag("Player");
}
private void Update()
{
if (m_Player.GetComponent<Player>().EnteredTrigger)
//Do whatever
}
}