Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Infinity · May 02, 2011 at 10:49 PM · multiplayerkeyboardkeysco-op

How to configure keys to let to players play

Hi, I want to have two players simultaneously in the screen, I have defined both characters with all their stuff, but I have a problem, they move all both together (of course because they have the same script). What should I do to modify to the script for the second player to let it play with different keys? (for example player 1 with WASD and player 2 with arroykeys)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by loramaru · May 03, 2011 at 03:20 AM

I would suggest making multiple inputs with a standard pattern that includes a player number, e.g. "Player1Left", "Player2Left", "Player1Up", "Player2Up", etc. Then add a player number property to your script and change your code to look for an input based on the player number

var playerId : int;

function Update() { if (Input.GetButtonUp("Player" + playerId + "Left")) { // move player left }

 if (Input.GetButtonUp("Player" + playerId + "Up")) {
     // move player up
 }

}

This allows the user to continue to customize using the standard configuration interface and allows for easy scaling up to more than 2 players.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1
Best Answer

Answer by Thomas 7 · May 02, 2011 at 10:56 PM

You could add a boolean UseArrowKeys and then check in your code if you use WASD or arrow keys. Make sure 1 player object has the boolean true and the other one false.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1
Best Answer

Answer by ShinyDarkStone · May 03, 2011 at 02:54 AM

you could create a class named playerControls that define which keys use each one on the constructor, then you can create a "configure keys" screen and let the user configure his keyboard using the each class.(lets say playerOneControl and playerTwoControl) Its a little complicated but more flexible and you can add the number of players you want, also add joystick support.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Infinity · May 07, 2011 at 11:05 AM 0
Share

How can I can create a "configure keys" screen?

avatar image ShinyDarkStone · May 09, 2011 at 12:58 AM 0
Share

Its a ltl long to expolain, but you sould use the GUI to create the menu and the buttons on the menu to set on the players class the keys.(its not hard to code and i think it worth it)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

co-op game? 1 Answer

How to make a simple co-op (2-player) Game? 1 Answer

Unity networking tutorial? 6 Answers

How to check if key is pressed 1 Answer

Check if there is a keyboard input (not a specified key input) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges