public TargetScript target;
void Hit()
{
target.BroadcastMessage("ApplyDamage",damage,SendMessageOptions.DontRequireReceiver);
}
}
Now, this works when I have ApplyDamage() under TargetScript. I have another script, also attached to the same object TargetScript is attached to. I want to receive the broadcast on the other script.
I tried target.gameObject.BroadcastMessage hoping it would get the gameObject target is attached to, then broadcast to all scripts attached to the gameObject, but this did not work.
Are you sure you have the ApplyDamage function in your other script as well (no typo or something)? Just tried it here and broadcast message to a target GameObject/Script (both) is received by all attached scripts that have the function.
It should work: target.BroadcastMessage(“ApplyDamage”, damage, …) calls the function ApplyDamage(damage) in the target script and in any other script attached to the same object or to any of its children. As @hathol said, check if the ApplyDamage exists in the other script, and if its name has no typos.