Troubling Refactoring on Windows

Hi all

I’m struggling with refactoring on Windows, the method Ben shows does not allow me to do it. I’ve looked at Ben’s code and compared to my own and i am unable to figure out what to do, it seem identical!

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            ShowMainMenu();
        }
        else if (CurrentScreen == Screen.MainMenu)
        {
            if (input == "1")
            {
                level = 1;
                StartGame();
            }
            else if (input == "2")
            {
                level = 2;
                StartGame();
            }
            else if (input == "501")
            {
                Terminal.WriteLine("LARA!!");
            }
            else
            {
                Terminal.WriteLine("Please enter a valid selection");
            }
        }          
    }

Because the right click method doesn’t work, i go to edit - refactor - extract method and i get the following error.

Any help will be much appreciated!

Hi Liam,

Assuming this script is already error free, it may just be that Visual Studio has it’s cache/debug symbols a little bit screwed up. You can try this to resolve that;

  • Within Visual Studio, right-click on the solution and select Clean Solution from the context menu
  • You will see some messages being output to the console during this brief process, you should end up with a message that states it completed successfully, there will be a number also which refers to the number of projects within the solution it cleaned
  • Right-click again on the solution and select Build Solution from the context menu, this will similarly output to the console and indicate success/failure. Note, if there are errors in your code you will not get a successful build.
  • Close Visual Studio
  • Within Unity, double-click one of your scripts to launch Visual Studio, this will automatically re-open the solution
  • Re-try your process of refactoring

Let me know what happens. :slight_smile:

1 Like

Amazing it worked!!!

Took me a while to get to where you said, but it nows works exactly how Ben’s had.

Life saver! Thank you!

:slight_smile:

1 Like

You’re very welcome. I was going to add some screenshots to make it a little clearer but I had hoped you’d get there without these.

I have responded to another student with a similar response in the past which had some screenshots - always worth a quick search on the forum to see if anyone else has had similar issues :slight_smile:

In fact, it was a little video, I’ll link it here in case anyone else reads this topic before the other, might help.

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

Privacy & Terms