- Home /
using inheritance for multiple attacks
I was wondering if I can use inheritance to create multiple attacks easily. Here is what I mean
Base Class public class ShootingAttack extends MonoBehaviour{
public var Target : Vector3;
public var HitParticle = "";
public var ShootParticle = "";
public var ParticleS = "";
public var Part_number : int = 1;
public var Damage : int = 1;
public var gravity : int = 0;
public var Cooldown : int = 5;
public var Move;
public var timer;
public function Start () {
//start
}
}
public function Update () {
}
public function PlayerAttack(){
// attack
}
and this would be inherited.
class Ember extends ShootingAttack {
public function start(){
super.HitParticle = "FireAt";
ShootParticle = "FireAt";
ParticleS = "Attack";
Part_number = 1;
Damage = 5;
gravity = 0;
Cooldown = 5;
}
}
and pretty much the base class would use the inherited values to attack so I can quickly create multiple attaks by changing values.
Answer by fafase · Oct 04, 2014 at 01:43 PM
You are misunderstanding the purpose of inheritance. In your case, what you want is different prefab on which you add the base class and pass the values in the inspector. Then each prefab is a ShootingAttack but with different skills and attributes. (Also it is Start and not start).
The purpose of inheritance is that you would create different type of ShootingAttack (like you are now) but some would have different behaviour though still being a ShootingAttack. For instance, you have a ShootingAttack that explodes and another that gets stuck to the target (arrow). Those two would have some common behaviours and variables like the fact they move like a projectile, have damage value and so on. But the on impact, they act different so you would sub class and implement differently.
As long as it is just a matter of values, use prefab only.
Your answer
Follow this Question
Related Questions
Does Anyone Have a Halo-Like Scripts? 1 Answer
I need help fixing this code 1 Answer
Already has a definiton for 1 Answer
Creation of RPG Class Stat Presets? 1 Answer
What is better for a game character? 1 Answer