Boss AI

I want to start learning some AI. So far ive learned to use scripts mainly as object components. I have a very good understanding of classes and objects as well as inheritance and i want to use those for my Boss AI. So my problem now is where do I create my scripts, aside from being components in game objects.

eg. I have 2 game objects (2 different bosses). both of them have similar properties that i want to put in 1 abstract class(health, damage). then 2 derived classes for their attacks in form of methods. then the game objects will have a script component that uses switch case to determine when to use an attack.

Where do I create or place those first 2 classes that i mentioned

Classes don’t have to be attached to game objects. You can just write the script and leave it as a file somewhere in your assets folder, and other scripts will be able to use it for inheritance, etc.

You can even create classes that don’t inherit from MonoBehaviour, and use them as plain C# objects with no relation to UnityEngine to do all the things you can normally do in plain C# outside Unity.

1 Like

I always use base classes that derives from MonoBehaviour for AI or Player classes. I make a scripts folder, have a sub folder for AI or Enemies and put all the classes in there to keep it organized. Sometimes even sub folders for enemy types. I also make one Character/Actor class that has all the properties that Players and AI have like health/damage/equipment and derive from that.

This ^^^

For complex systems I tend to only put code into MonoBehaviours (or classes which inherit from MonoBehaviour) which directly applies to the GameObject in the scene or for interacting with the system, and the inner workings of the system will be in C# classes which don’t inherit from MonoBehaviour.

heres the system that i can understand from you guys. so i have a bosses class(health, damage) which derives 2 boss ai classes(attack functions) bossai1 and bossai2.

and then another script that is derived from monobehaviour will be attached to boss1 for example that will instantiate bossai1 and use that guys functions and setvariables in the start and update functions.

sounds solid so far, any comments for this?

Edit: i realize that the bossai with attack functions would probably need to be derived from monobehaviour since they will have movement in them that will use the update