A
A
Artem Zuev2020-12-16 13:59:14
C++ / C#
Artem Zuev, 2020-12-16 13:59:14

Why is the if statement not working?

In my game, an enemy spawns every timespeedsecond.
B is constantly decreasing and if it should stop decreasing, but in the Inspector in Unity, you can see that it continues to decrease. Here is my code:Void Update() timespeedtimespeed == 0.5f

public float timespeed = 1.5f;
    void Update()
    {
        if(timespeed != 0.5f)
        {
            timespeed = timespeed - 0.000002f;
        }
        else if(timespeed == 0.5f)
        {
            timespeed = timespeed;
        }
   }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-12-16
@18382774

Because it is not equal to 0.5, but is equal to some 0.49999999999999

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question