I have bullets:
public LaserBullets : Projectile
I have a gun that inherits from a base weapon with the bullet type that goes with the derived gun:
public LaserWeapon : Weapon<LaserBullets>
I have a property to establish the current weapon of a player:
public Weapon<Projectile> CurrentWeapon
{
set { currentWeapon = value; }
}
This fails (cannot implicitly cast LaserWeapon
to Weapon<Projectile>
)
player.CurrentWeapon = new LaserWeapon();
I've read about no support for certain covariance in C#, but I don't want to think that I'm stuck here. Is there any way to make my situation work? I'm trying to maintain a base weapon in the player class but work with a more specific weapon in another class.
I tried creating my own cast operator for LaserWeapon but I got an error about being unable to cast to/from base class.