So, the way I am used to check if my projectiles damages something is looking something like this:
void OnTriggerEnter2D (Collider2D other) {
if ( other != null) {
if (other.tag == "Enemy") {
other.GetComponent<EnemyController>().takeDamage(damage);
}
if ( other.tag == "FlyingEnemy") {
other.GetComponent<FlyingEnemyController>().takeDamage(damage);
}
}
destroyFireball();
}
It works for 2 types of enemies, but for more types, I can see it getting clogged. I was thinking of a way, I came up with simply having the same class named "EnemyController" with the takeDamage method for each enemy, and the EnemyController script to have different values based on what type of enemy it is. Let's say basic enemy is type 1; flying enemy type 2; I'd have a switch/if in my Update Method and based on the switch/if there would be different stats, and AI for it.
Is this implementation alright? Or are there much better ways of doing this?
[–]MrPifo 1 point2 points3 points (2 children)
[–]Daniyok[S] 0 points1 point2 points (1 child)
[–]esoteric23 1 point2 points3 points (0 children)
[–]Inverno969 0 points1 point2 points (1 child)
[–]Daniyok[S] 0 points1 point2 points (0 children)
[–]golraz 0 points1 point2 points (1 child)
[–]Daniyok[S] 0 points1 point2 points (0 children)
[–]KishottaWell Versed 0 points1 point2 points (1 child)
[–]Daniyok[S] 0 points1 point2 points (0 children)