In Unity, the way to execute a method from another script is as follows:
Objeto.GetComponent<NomeDaClasseDoScript>().NomeDoMetodo();
Or
Objeto.GetComponent("NomeDaClasseDoScript").NomeDoMetodo();
The second form has performance disadvantages (because you need to do the reflection in a sense similar to what @bigown has described to you), but it works for what you want. So, you can do it as follows:
Create different scripts instead of different methods in a single script. Each script will have the name you are defining (in transform.name
). And all of them will have the same method animation
(of course, each doing what it has to do differently).
Run the method as follows: Enemy.GetComponent(Enemy.transform.name).Animation();
. Note that this may generate errors during the execution of your game if the script with the name Enemy.transform.name
does not exist!
That said, I would like to mention that I understood what you want to do but did not understand exactly why you want to do this. You are centralizing the control of the animation in a class called AnimationManager
, when you could have left it to the class of each enemy (the enemy can also detect the collision and alone execute its animation). From the point of view of object orientation this is a very bad choice, as it creates an unnecessary coupling and will certainly hinder its future maintenance.