Help please Stuck on something Weird

Hi,

I have this variable:

public bool damageOutPutReducedWithVelocity;
float velocitySwitchMultiplier = 1;

On start function I have:

if (damageOutPutReducedWithVelocity)
        {
            Debug.Log("true");
            velocitySwitchMultiplier = 1f;
        }
        else
        {
            Debug.Log("false");
            velocitySwitchMultiplier = 0f;
        }

I have “damageOutPutReducedWithVelocity” Checked so Debug>Log Returns “true”

However, the following when ran inside a function returns 0 “Zero”;

Debug.Log(velocitySwitchMultiplier);

There is no update function in this script.

Thanks in advance

Can you post the whole script? The issue is probably somewhere else in it, or you’ve got another instance of the script in your scene you’re not aware of.

1 Like

Please attach or show your whole script.

1 Like

@JeffDUnity3D , @Joe-Censored

Thanks for reply

I don’t see you using it anywhere else, where is it returning 0?

1 Like

Are you sure your Debug.Log messages for “true” and “0” are for the same instance of this script? You can add gameObject.name to your two debug statements to verify they are from the same GameObject.

1 Like

ok let me go do that

Also Please ignore that false, its coz my enemy has the Script also and the false turns off when I switch off the enemy:

But without enemy I have nothing to attack so I cant show u that the other Log returns Zero;

Where is that “false” debug message coming from?

And I meant literally putting gameObject.name

Debug.Log("true " + gameObject.name);
Debug.Log(gameObject.name + velocitySwitchMultiplier);
1 Like

turned it on for the enemy also to clear the confusion:

But how do you know the velocitySwitchMultiplier value of 0 in the console isn’t coming from the script instance reporting false, when you know the only way it could be 0 is if it previously reported false?

My assumption would be that is the case.

1 Like

I notice no more false, and no more 0. Only true and 1 now.

1 Like

your right but I dont understand whats happening.
because my ToonSoldir cant even call that function… my head about to explode

1 Like

Oh the fun of debugging! Glad you’re getting a bit closer though :smile:

1 Like

I got it, I am an absolute idiot!!!

I should of put that option “velocitySwitchMultiplier” on the script that is dealing damage not the one receiving it it!

1 Like

This is so embarrassing lol!

Thanks a lot bro! your a star!

2 Likes

If you were an idiot, you wouldn’t have ever got it. Smart people make mistakes too, and sometimes have trouble seeing them because they think stupid decisions are beneath them. :stuck_out_tongue:

2 Likes