c# 2D game - how can i implement 2 players on the one keyboard?

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.

  1. Go to Edit > Project Settings > Input

  2. Create a new entry called “Horizontal Player2” and specify the keys for your 2nd player

  3. 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;

Hello @wipeout245 !

But what do you need? Do you want to know how to control another player?

Using GetKeyDown

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.