Hello. Trying to do something to an object while that object is in a 2d trigger collider but not until a button is pressed.
Ive done ALOT of experimenting on this. it looks like values will not update once they are in the trigger collider function, including values that are calculated outside of the ontrigger if the function or value is called inside the trigger.
I think if the following code can work, I can figure the rest on my own. The desired result is that when elements are in the trigger and the button is pressed, the console has logged. The variable in the trigger never equals true though for some reason. I have tested this by logging the variable both in and out of the update function.
private void Update() {
if (Input.GetKey(KeyCode.Space)) {
testIt = true;
} else {
Debug.Log("not held");
testIt = false;
}
}
private void OnTriggerStay2D(Collider2D otherObject) {
if (testIt) {
Debug.Log("meow");
}
}
Im using unity version 2019.3.0f6 personal