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:
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;
}
}
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.