Hi friends!
I have an enum member in my base class that I want to change from my derived class in the declaration section.
I manage to do so but unity gives me a warning that the “is assigned but its value is never used” although I do use it.
can anyone please help me understand what i’m doing wrong here? and how can I get rid of this warning?
I have a space ship that has modules, when the ship is initialized I check for the module type and instantiate the corresponding game object
CreateSlotsModules()
private void CreateSlotsModules()
{
int j = 0;
foreach (var slotData in ShipConfigData.Slots) // loop through slots in the ship config data
{
if (!slotData.Module) // if object is empty skip iteration
{
j++;
continue;
}
SlotModule slot = slotData.Module.GetComponent<SlotModule>(); // get the slot module's base class
switch (slot.Type) // <----------- this is where I use the variable
{
case Enums.SlotType.Weapon:
CreateWeaponModule(j, slotData);
break;
case Enums.SlotType.Shield:
CreateShieldModule(j, slotData);
break;
case Enums.SlotType.System:
break;
case Enums.SlotType.Armor:
CreateArmorModule(j, slotData);
break;
}
j++;
}
}
Module Base Class
public class SlotModule : MonoBehaviour
{
public Enums.SlotType Type;
public Collider SlotCollider;
public ShipConfiguration ShipConfiguration;
void Awake()
{
gameObject.layer = 16;
}
public virtual void WasHit() { }
public virtual void Repaired() { }
}
Module Example - derived class
public class ShieldModule : SlotModule
{
new readonly Enums.SlotType Type = Enums.SlotType.Shield; // <------ this is where I assign the enum
public float ModuleShieldPoints;
public float RechargeDelay;
public float RechargeRate;
public float SPAfterRestart;
public float RestartTime;
public override void WasHit()
{
ShipConfiguration.UpdateShipShieldPoints(-ModuleShieldPoints);
SlotCollider.enabled = false;
Debug.Log("Shield Module down");
}
public override void Repaired()
{
ShipConfiguration.UpdateShipShieldPoints(ModuleShieldPoints);
}
}