c# - Problem with object health

i’ve been messing around with this for a hour or two now and i can’t figure out where I’m going wrong.

I have an object that has the properties Strength & Resistance. what i’m trying to do is reduce the strength of the object by speed (which is pulled from another game object) minus the resistance when the mouse button is pressed inside the Update

So im thinking

Strength - (speed - resistance).

ive tried every math combination i can think of an its give me every result but what I’m looking for.

You have to be more precise in describing the issue.

You need to realise that your dealing here with 3 objects(character, other object, and mouse/mouseOver) so you need to break down this math. Reduce the strenght by res and speed separately.

Additionally you have to deal with the TIME here. If you reduce strenght in update it will be reduced every frame.

I think the solution here is to make the calculation in awake and apply results in Update/OnTrigger.