How can I emit a global function call?

I’m looking to create a function that behaves similarly to the built in Unity functions Update(), Start(), Awake(), OnCollisionEnter(), etc.

I would like to place a function in several scripts and call all of them at once. For instance, let’s say I want to create a touch tracking function that will emit something like “touch_started()” and “touch_ended”.

I’d like to be able to add those functions to any number of scripts and have them get called from a different touch tracking script. I don’t want to manually call all of the instances where they are defined.

Rather than:

world_1_script.touch_started();
world_2_script.touch_started();

I’d like to be able to do something like:

*.touch_started(); 

(Obviously that’s not going to work and isn’t proper code. It’s simply an example to illustrate my objective)

Any help would be greatly appreciated. Thanks

Duplicate Question!

Hope this helps,
Benproductions1

I saw that this question started getting lots of views so, despite it being a duplicate question, I’m going to post the proper answer I was looking for in case other people find it useful and don’t feel like clicking and reading another question.

To globally call a function in any script, you actually use SendMessage(). Here is an example:

gameObject.SendMessage("touchStarted", someValue);

That will cause every function named “touchStarted” in every script (C & JS) to fire:

function touchStarted(someValue:float) {
    print(someValue);
}

Pretty awesome.