[Solved] Object Reference required for property?

I’m returning a property in a function and using it again in another function. I get this error:

“An Object reference is required to access non-static member”

The line that has the problem is:

void Counter(Damage damage)
    {
        damage.Target.takeDamage(damage);
        if(damage.Target.HP > 0) //SCALE WITH ATTACK (PLACEHOLDER 15)
            DamageManager.DealDamage(damage.Target, damage.Attacker, Damage.E_Context.Counter, Damage.E_DamageType.Physical, 15); //ERROR
    }

The DealDamage method requires a Character (another class I made) as a attacker, another one as a target, a enum which specifies the context of the damage (In this case it is a counter, that’s why target and attacker are switched), a enum to specify the type of damage and a value (15 is a placeholder),

This function recieves a Damage instance, which has all the elements formely mentioned.

damage.Target and damage.Attacker are properties so i only have a get inside it.

Just means you need to reference it as an object and then call the function.
In start maybe just do something like DamageManager dmgMngr = new DamageManager();
and then you can call it as dmgMngr.DealDamage(etc)

… I think … :smile:

1 Like

It’s exacly that thanks :smile:

btw can you close a thread, it’s answered so i don’t know how to

The forums don’t work like stack/answers, there’s not a way to accept an answer or close them manually because threads are just discussions.

1 Like