Change a Class in the inspector

I have a class with my basic enemy AI in it and I have created several AIs that inherit from that one. What I would like to be able to do is create a new prefab throw my script that uses the class on it and then drag my desired AI to the variable in that script. However I cannot find a way to do this. I have done some Google searches with no luck.

Sounds like what you’re looking for are Interfaces. Have a look at the documentation.

Essentially, you’ll want all of your AI scripts inheriting from an IArtificialIntelligence (I wrote it out cause IAI looks dumb, lol) that enforces methods and properties shared on all AI scripts. Then you can simply set an IArtificialIntelligence AIscript; as a class member and shoud be able to drag and drop anything inheriting from it into that box. :slight_smile:

Spend some time to understand Interfaces. They’re wildly useful and amazing, and are seriously underrated.

EDIT: Ok, lame. I just noticed the javascript tag. This won’t help you. In fact, there may not be a way to do what you want in Javascript. So I know that this isn’t the answer you’re looking for, but please hear me out. Javascript is NOT, I repeat NOT a good language for developing large games in. I’m honestly surprised Unity implements it at all. I kind of feel like doing so was a marketing thing to attract more users. I don’t dislike javascript – it’s pretty cool, but not for Unity. It’s fairly similar to C#, so take some time to get to know C# and you’ll find yourself dealing with significantly less bugs. Anyway. Good luck to you!