I have a GameObject with a SphereCollider as a trigger around it that should rotate towards another Object entering that trigger (I use OnTriggerStay here).
Now I want that trigger to ignore every other Object entering it as long as there is an Object staying in the trigger. I have abolutely no idea how to handle that…
In simple: If the trigger is triggered i don’t want it to be triggered by anything else but the object inside the trigger.
well you can use OnTrigger enter to store the object, have an if statement that only changes it if it’s null,
in the OntriggerStay() check if the stored gameobject is the same as the one in the OntriggerStay, do the rotation.
in the OntriggerExit set the stoged gameobject to null
I wont give you code cause i dont remember it lol but i can guide you. When the trigger is triggered, it stores the object that triggered the event. So its a matter of doing something like event.target, i dont remember the exact name but intellisense will help.
In the other hand if you want to deactivate the trigger, just get the component with a GetComponent or something in that line. if your guy that activated the trigger leaves, and while the collider is deactivated, you should use a distance method to calculate how far he is, for this u can use Vector3.distance. when its value is above lets say 5, you activate the collider again.