Calling a function from same script, on different objects, through Inspector.

Hey guys, I’ve been trying to do this for a few hours now and can’t seem to find a solution online.

As the title says, I want to have a bunch of functions in a single script, that I can place on different gameobjects, and be able to call the function I want for each gameobject, through the Inspector.

I have a bunch of environmental assets that do a variety of different things. I have the functions already written and working, but would like to combine them into a single script, if possible.

Thanks in a advance!

First, create an editor script and add a way to execute a function (MenuItem, EditorWindow, …).

Then, get all the components you want in your scene.

MyScript[] objects = GameObject.FindObjectsOfType( typeof(MyScript) );

Finally, call the function

foreach( MyScript ms in objects ) objects.MyCoolFunction();

Now, if those objects have the same script but you want a different behaviors on some of them, use an enums or a boolean (or whatever you want) to determine what the function should do.

Great, got it to work, thanks very much, Berenger!