When I instantiate a new class I’m able to open up brackets to change many properties at once ex:
public class Damage
{
public int amount;
public bool isCritical;
public Element element;
}
//...
Damage outgoingDamage = new() { amount = 100, isCritical = true }
But I can’t figure out if it’s possible to do that same thing with an existing instance of a class. For example, my stats class calculates the base damage and if it’s going to be a critical or not, but then my MeleeAttack class considers the elemental properties of the weapon and may need to make more changes.
public Damage InitialDamageCalc()
{
return new Damage { amount = power, isCritical = true };
}
//...
public Damage FinalDamageCalc()
{
Damage newDamage = stats.OutgoingDamage();
newDamage.amount = 400;
newDamage.Element = Element.fire;
return newDamage;
}
Is it possible to open up the brackets on stats.OutgoingDamage() so I can edit it as if I were instantiating a new instance of the class? Something like:
public Damage FinalDamageCalc()
{
Damage newDamage = stats.OutgoingDamage() {
amount = 400,
Element = Element.fire
}
return newDamage;
}
//OR
public Damage FinalDamageCalc()
{
return stats.OutgoingDamage() {
amount = 400,
Element = Element.fire
}
}