I don't know a whole lot about Unity and I haven't done game development in a while, so let me give you general programming answer to this question. I have based my answer on the knowledge I have about entity-component systems in general , where an entity is a number that is associated with N many components, a component only contains data, and a system operates on sets of components that are associated with the same entity.
Your problem space is this:
- There are multiple ways of attacking an enemy in the game as whole.
- Each ship, structure, etc, may have multiple ways of attacking (each determined by some manner)
- Each attack may have it's own particle effects.
- The attack must factor in some factors (such as inertia, or armor, for example), that are present on the target and on the user.
I would structure the solution like the following:
- An attack has an identifier - this could be a string.
- An entity 'knows' that it can use an attack (based on the identifier of the attack).
- When the attack is used by the entity, the corresponding display component is added to the scene.
- You have some logic that knows about the target of the attack, the attacker, and the attack being used - this logic should decide how much damage you do (and have access to the inertia or whatever of both entities).
It is important that the point of contact between the attacks and the entities are as thin as possible - this will keep your code reusable and prevent you from having to come up with duplicate code for each different type of entity that uses the same type of attack. In other words, here's some JavaScript pseudo-code to give you an idea.
// components
var bulletStrength = { strength: 50 };
var inertia = { inertia: 100 };
var target = { entityId: 0 };
var bullets = {};
var entity = entityManager.create([bulletStrength, inertia, target, bullets]);
var bulletSystem = function() {
this.update = function(deltaTime, entityId) {
var bulletStrength = this.getComponentForEntity('bulletStrength', entityId);
var targetComponent = this.getComponentForEntity('target', entityId);
// you may instead elect to have the target object contain properties for the target, rather than expose the entity id
var target = this.getComponentForEntity('inertia', targetComponent.entityId);
// do some calculations based on the target and the bullet strength to determine what damage to deal
target.health -= ....;
}
};
register(bulletSystem).for(entities.with(['bullets']));
Sorry this answer is a bit 'watery'. I only have a half hour lunch break and it's hard to come up with something without knowing fully about Unity :(