1
\$\begingroup\$

I want to change a bool in 2 separate scripts in Unity but it's not changing OnTriggerEnter or stay or exit. I've tried everything but nothing helped me.

This is the script where I store the bool and the animator script:

public Animator _T1anim;
public bool Open;


void Awake()
{
    _T1anim = GetComponent<Animator>();
    _T1anim.SetBool("Open", false);
    _T1anim.SetBool("Close", true);
}
public void Update()
{
    if (Open != true)
    {
        CloseDoor();
    }
    else
        OpenDoor();
}
public void OpenDoor() {              
        _T1anim.SetBool("Open", true);
        _T1anim.SetBool("Close", false); 
}
public void CloseDoor()
{
    _T1anim.SetBool("Close", true);
    _T1anim.SetBool("Open", false);
}

and I want to change the "Open" Bool to true with the OnTriggerEnter in a different script. The T1_1 T11 is the reference to the first script.

T1_1 T11;

void Awake()
{
    T11 = GetComponentInParent<T1_1>();        
}
public void OnTriggerEneter(Collider other)
{

    if (other.tag == "Player")
    {
        T11.Open = true;
    }

}
}

This is the animator controller:

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Please edit the title of your question to be a brief question. Try to keep descriptions of the problem in the body of the question itself. Meanwhile, we should be able to get you a helpful answer. Welcome to SE.GD! \$\endgroup\$
    – Stephan
    Commented Oct 26, 2018 at 19:06
  • 1
    \$\begingroup\$ Note: There's a typo in OnTriggerEneter in the second script. \$\endgroup\$ Commented Oct 28, 2018 at 6:42

2 Answers 2

1
\$\begingroup\$

OnTriggerEnter is only called when one object' collider is set to Trigger and the other object also has a collider attached. Also one of the objects must have a rigidbody. See the Unity docs: https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

"Description

OnTriggerEnter is called when the Collider other enters the trigger.

This message is sent to the trigger Collider and the Rigidbody (if any) that the trigger Collider belongs to, and to the Rigidbody (or the Collider if there is no Rigidbody) that touches the trigger.

Notes: Trigger events are only sent if one of the Colliders also has a Rigidbody attached. Trigger events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. OnTriggerEnter occurs on the FixedUpdate after a collision. The Colliders involved are not guaranteed to be at the point of initial contact."

Hope that this helps

\$\endgroup\$
1
  • \$\begingroup\$ The player charater has rigidbody on it's collider but i will read through the link thx. \$\endgroup\$ Commented Oct 26, 2018 at 19:46
-6
\$\begingroup\$

Do you know what a boolean is its false or true but also could be 1 or 0 if you can set the bit by OR 1 or AND0 to clear

I think T1_1 T11;set in other script make a local copy for that script not a global edit to the original variable.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .