For my 2 player game I have 2 player spawners, one for each player. When they are spawned they are named player1
and player2
respectively.
What I want to do is have some sort of statement that sets player1
ās controls to certain inputs (WASD
) and player2
ās to a separate control scheme (Arrow Keys
).
Could anyone help? Iām really scratching my head at this.
ps I would post my current code if I knew how to format it for this website
public KeyCode forward;
public KeyCode back;
//the attacks will be added later, just trying to workout how to allocate the different controls
public KeyCode Hattack;
public KeyCode Lattack;
public KeyCode Hblock;
public KeyCode Lblock;
Rigidbody2D rb;
[SerializeField] float speed;
float mx;
private void Start()
{
//im assuming i want to put the if statement in the start section
rb = GetComponent<Rigidbody2D>();
forward = KeyCode.A;
back = KeyCode.D;
Hattack = KeyCode.R;
Lattack = KeyCode.T;
Hblock = KeyCode.F;
Lblock = KeyCode.G;
}
private void Update()
{
if (Input.GetKey(forward))
{
transform.Translate(Vector2.right * (Time.deltaTime * speed));
}
else if (Input.GetKey(back))
{
transform.Translate(Vector2.left * (Time.deltaTime * speed));
}
}
}