O'Reilly logo

Unity Game Development Scripting by Kyle D'Aoust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Let's switch!

Now, we'll create a way for the player to switch between PC and Xbox 360 Controller controls.

Creating control profiles

To create our profiles, we'll need to add a new variable. Add the following enum to the top of our script, before the class declaration:

public enum ControlProfile { PC, Controller };

Add it to your variables as well, like this:

public ControlProfile cProfile;

Finally, go to the DetectController() function. Add this line of code before the line of code where you call the IdentifyController() function in the if statement:

cProfile = ControlProfile.Controller;

After this, add an else statement to the if statement with another line of code after it:

else
  cProfile = ControlProfile.PC;

We are setting our enum variable in the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required