I have a bunch of enemies, each has a script for their own behavior, though they have the same kinds of stats (hit points, etc.). Right now I have a script called EnemyScript and when I need to change something, I use GetComponent(), and that works fine. But I need to change the script being referenced in GetComponent depending on what kind of enemy is acting.
Is it possible to change the script being referenced in GetComponent()?
Oh my gosh, oh my gosh! It’s time to learn about polymorphism and interfaces! I’m excited for you! :B
These articles discuss the strategies that will ultimately satisfy your request. I suppose it’s possible there are alternatives (like exactly what you’re asking for), but it would be irresponsible to suggest them. It’s much better to learn to utilize the constructs of object oriented programming. I never even learned how to do exactly what you’re asking for, because it’s a grossly inferior strategy. Asking this type of question tells me it’s time for you to learn about these principles before moving any further down the wrong path.
That guy’s C# reference guides are a goldmine, by the way. Totally worth starting at the beginning and reading each article.