Setting variable in Switch or Method

When I did the challenge for this lecture I put the isTransitioning = true within my switch vs within the method the switch case is calling (like Rick did in the video). Is there a reason to do this in the method vs within the switch? Both work.

Example:

 void OnCollisionEnter(Collision other) 
    {
       if (!isTransitioning)
        {
            switch (other.gameObject.tag)
            {
            case "Friendly":
                break;
            case "Finish":
                StartSuccessSequence();
                isTransitioning = true;
                break;
            default:
                StartCrashSequence();
                isTransitioning = true;
                break;
            } 
        }
    }
1 Like

Hi,

I do not see any reason why you should not solve the problem like this. If you like your solution, feel free to keep it. :slight_smile:


See also:

1 Like

The only problem would be if you call one of those methods from somewhere else, it will not update the isTransitioning variable, but since we are not it should be fine

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms