Inheritance Backwards

Hi everyone,

This is probably a noob question… but I can’t seem to get around it. I tried googling it but most of the people posting this has problem with virtual methods…

I have a base class called Items.cs

I have a sub class called weapon that inherit from it.

public class Weapon: Items {  
  
		public DamageGrouper[] damageTypeDealt;

	    }

And I have an Inventory system that has a variable like this:

public Items handSlot;

The slot is Items so it can get assigned a weapon or something else.

The prolem is that when I try to call the weapon from another script I adress the handSlot variable but when I do, I can’t call the DamageGrouper variable, as I’m adressing the base class and not the derived class.

Is there some method like GetComponent but for classes?

Thanks in advance.

Try this:

Weapon weapon = handSlot as Weapon;
weapon.damageTypeDealt = ...

In this expression as works like GetComponent for Gameobjects.