(Beginner) How to switch between WASD<-|->Arrow Keys controls for specific player GameObject?

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 :confused:

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));
        }
    }
}

There are many ways to do that , that go from stupidly simple to very complex/contextual.
I suggest a very simple first solution that uses ScriptableObjects.
You can create a ScriptableObject like so :

[CreateAssetMenu(fileName="PlayerControls" , menuName="Data/PlayerControl")]
public class PlayerControlsAsset : ScriptableObject
{
     public KeyCode forward;
     public KeyCode backward;
     public KeyCode left;
     public KeyCode right;
}

You can create 2 of these assets , one that uses WASD and another that uses arrows.
Then in your player GameObject , make sure your script get the input using the asset
something like

public class PlayerController : MonoBehaviour
{
    [SerializeField]
    private PlayerControlsAsset controls;

   void Update()
   {
          // just an example of how to get the key value
           if(Input.GetKey(controls.forward)) transform.position += Vector3.forward;
           // TODO : etc ...
   }
}

Hope this helps

Try using tags. If you made the players two separate objects, with the same script attached to both, you could easily create that functionality. player1 is tagged "player1" the opposite for player2. The have the script check,

if(this.tag == "player1")
{
   //WASD
}
else if(this.tag == "player2")
{
  //Arrows
}

This should work.

//uses the position and rotation of "Player1Spawner" to place our character into the FIGHT SCENE
private void Start()
{
    var Player1 = Instantiate(GameManager.instance.currentCharacter1.prefab, transform.position, Quaternion.identity);
    Player1.name = "player1";
}