How can i plus up a float with out constantly updating it?

Hello everyone.

I have this issue but idk if this is just a common programming problem or a Unity3d problem.

Well see I have this statement that says this.

		if (Thinking == 2 && !Attacked) {
			//Blocking

			Defense = Defense + 20;
			StartCoroutine("Blocking");
}

If I get a 2 and what not, the AI begins blocking.

But when I add my Defense with a + 20, it constantly goes up each and every frame.

I thought it would only plus them together once. But I see that since if my Thinking is remained as 1 it will constantly update. Yeah that’s great but I don’t want my numbers to keep increasing. I only want it to do this.

If Thinking == 1

Defense + 20 = NewDefense;
or
Defense + 30 = PlusdUpDefense;

Basically like a standard calculator that doesn’t keep adding itself.

Add an additional float property: baseDefense

public float getDefense() {
    if(blocking) {
        return baseDefense + 20;
    }     
    return baseDefense;
}

Ok, Nvm guys. I “ThoughOf” (Haha) A better idea that works. Took me long enough though. Here’s the Code.

		if (ThoughtOf == 2 && !Attacked) {
			//Decided to Block
			Defense += 20;
			ThoughtOf = 0;
			StartCoroutine("Blocking");
			Thinking = 2;
		}

So at that very Second my AI has decided to execute that function. Then since they Executed that function they will continue to do what ever they declared until something else happens. So Thinking will remain as 2 until yada,yada, ya.

Now If I ever want something to Executed once perframe for my AI I’ll just put it there. Works fine, I like it!

Thanks for the Support dudes!