Hi, I have a simple script here :
function OnTriggerStay (col : Collider) {
RateCount += Time.deltaTime;
if (RateCount >= Rate){
col.SendMessageUpwards(“DOthis”, damage, SendMessageOptions.DontRequireReceiver);
RateCount = 0.0f;
}
}
Basically what I want this script to do is send a message with a rate count to everything in the trigger, bu it only sends a message individually to each object in the trigger with a rate. The wierd thing is, if I remove the “rate” part, the script works fine sending messages to everything in the trigger. Been searching the forums for hours, still no luck. Please help in JS, Thanks!!!
The OnTriggerStay
function gets called once, per frame, for each collider inside the trigger (maybe only once per GameObject if it has more than one collider, I’m not sure). SendMessageUpwards will only call DOthis for that object and its parents, not any children or ‘sibling’ objects, and certainly not any random objects.
If you need to send a message to multiple objects, you can either keep a separate list of objects, or obtain the list anew when RateCount>Rate, using something like GameObject.FindGameObjectsWithTag(..)
or similar method, to gather all the proper objects that should receive the message.
If you remove the rate part, what you get is simply each object in the trigger receiving the message individually. With the rate part, you’re resetting RateCount when it >= Rate, so only the very first object will ever get that message, per ‘iteration’.