Best paradigm for simple (non-component) scripts?

I'm new to Unity, so forgive me if I'm thinking about this the wrong way.

What I'm looking for is a way of creating simple scripts, that ideally contain a single callable function, that I can write inside the asset manager and then drag and drop into some public property of another script.

Here's an example application:

We have a generic AIEnemy component, that we add to enemy characters in a game. It contains an array of Ability objects, which contain properties like the ability name, the cost to invoke the ability, and some "function" that gets called when the ability is invoked.

The functions should be able to be defined in separate script files, and linked into the enemy data within the editor. Specifically, I should be able to add a new ability WITHOUT modifying my AIEnemy.js file.

1 Answer

1

You could simply make a public string property with the name of the function that gets called, or possibly even a string array with multiple function names

Then you could use

SendMessage(functionName, SendMessageOptions.DontRequireReceiver);

to fire that function in all the scripts attached which use that function - and if you're using an array of function names, you could just loop through them