If you have a base class (Weapon) and want some properties to be accessible by their childs, you have to declare them as protected.
class Weapon
{
protected int power;
protected int max_speed;
protected int count;
protected Prefab weaponPrefab;
}
If you need a constructor for a class, it has to have an access modifier:
class Bazooka : Weapon
{
public Bazooka()
{
power = 10;
max_speed = 100;
weaponPrefab = BazookaPrefab;
}
}
Next: a prefab is not a type in unity that you can use. Usually a prefab is a GameObject. So declare it as
class Weapon
{
protected int power;
protected int max_speed;
protected int count;
protected GameObject weaponPrefab;
}
To use a prefab, you have to create an Instance of this object. This is done by declaring a public GameObject variable in a script and manually drag the Prefab to this script, or with the Method Instantiate in code.
Use GameObject instead of prefab
ex. private GameObject weaponPrefab;
there is no point on creating a class for each weapon as it seem you are doing.
Just add on your Weapon class a field “name” (and an ID it s easier to refer to) and use it on all your weapons by Creating a Constructor (or a simple function to define its attribute accordingly)
public class Weapon {
public string name;
// and so on for all stats
//Constructor
public Weapon (string name,//add all stats as params){
this.name = name;
//the rest stats
}
}