I need something to detect like "OnTriggerStay" does, but that I could call whenever I want.
I need to detect objects in a specific zone, but not every frame because it consume too much CPU.
asked Nov 29 '10 at 10:57 PM
Try this code on. It will call the method < callbackName > with a callback of your choosing. framesToSkip is the number of frames that should be skipped until the next callback is raised.
Or if you'd rather have it time based:
Then your others scripts can be implemented such as:
Note that you can rename the callback you want to use. Don't use OnTriggerStay, OnTriggerEnter or OnTriggerExit since the latter two will produce errors and the first will cause unwanted behaviour.
In case you want to control when to send the event yourself, you could use this base class:
I think you need to override OnTriggerEnter and OnTriggerExit to call base.OnTriggerEnter and base.OnTriggerExit in your script. I am too lazy to check this now. I marked RaiseCallback sealed because there isn't really any intention for you to change its behaviour. Your code should instead just call RaiseCallback("OnTriggerWhatever"); whenever you find it fitting.
you could turn it around and make the zone a trigger and not the objects
answered Nov 30 '10 at 01:02 AM
You could assign it to a variable and turn the gameObject having the trigger on once every 5 seconds.
answered Dec 22 '10 at 05:51 PM