OntriggerStay - Can this function return boleans ?
Hi,
(Sorry for my english) I'm new into unity scripting basics and i just asking myself about the OnTriggerStay function.
Are this function return "inverse variable" when not true ?
For exemple :
void OnTriggerStay(Collider other) {
if (other.GameObject.Tag == "Player")
Asimpleboolean = true;
}
Can This function "auto-return" "Asimplebollean == false;" when the player in out ?
I know i can use OnTriggerEnter and OnTriggerExit but for optimisation purposes i think it's better to have less line in the code.
Thanks you :)
I think you should not violate Unity's programmatically standards, because code's readability and standards is more improtant then saving some lines of code (at least in this case). So please use OnTriggerEnter & OnTriggerExit, because calling OnTriggerStay manually is bad practice
afaik OnTriggerStay will only fire if something is inside the trigger's bounds. If nothing is inside the trigger's bounds then the function will not be called.
Unless you have a boolean that will constantly reset itself every frame in Update() and you set it back through OnTriggerStay, but you'd be better off using OnTriggerEnter and OnTriggerExit to track the enter / exit of objects in the trigger.