- Home /
c# 2D game - how can i implement 2 players on the one keyboard?
Hi, So I've made my first game in unity recently, and i decided to upgrade it. I wanted to make it so i could have to players playing at the same time on the same keyboard, using A and D as well as the arrow keys, but i cant find the right script to suit my needs. I think I've covered it all, here is my script:
Thanks in advance.
Is the multiplayer via a network or do you just want two instances of different Player class with key input? Can you show your keyboard input code?
Answer by Hellium · Sep 13, 2017 at 02:22 PM
Go to
Edit > Project Settings > Input
Create a new entry called "Horizontal Player2" and specify the keys for your 2nd player
Change the code as follow :
public class Player { public string HorizontalAxis = "Horizontal" ; // In the inspector, specify "Horizontal Player2" // ... void FixedUpdate() { float x = Input.GetAxis( HorizontalAxis ) * Time.fixedDeltaTime * speed; } }
Answer by tormentoarmagedoom · Sep 13, 2017 at 01:30 PM
Hello @wipeout245 !
But what do you need? Do you want to know how to control another player?
Using GetKeyDown
Answer by kaplica · Sep 13, 2017 at 01:37 PM
If I'm guessing correctly on what you want to achieve then you need to have two different instances of Player, and assign different keyboard controls to each of them. That way you will have 2 Players in the game, with different controls but with all the same behaviour. You can make the player a prefab, then instantiate the prefab and assign the right controls, obviously you have to instantiate two instances.
I would need more information from you to help you more.
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
2D movimentation "Lag" 0 Answers
Character doesn't jump repeatedly 1 Answer
Simple AI In 2D - C# 1 Answer