Commit f2431858 by Philipp Adolf

Move player initialization into new method

parent 6f542fd8
......@@ -61,32 +61,39 @@ public class PlayerControl : MonoBehaviour
{
body2D = GetComponent<Rigidbody2D>();
switch (playerNumber)
{
case 1:
keyCodes[(int)Keys.Right] = KeyCode.D;
keyCodes[(int)Keys.Left] = KeyCode.A;
keyCodes[(int)Keys.Up] = KeyCode.W;
keyCodes[(int)Keys.Jump] = keyCodes[(int)Keys.Up];
keyCodes[(int)Keys.Down] = KeyCode.S;
keyCodes[(int)Keys.Dash] = KeyCode.Space;
keyCodes[(int)Keys.Shoot] = KeyCode.LeftShift;
break;
init(playerNumber);
}
case 2:
keyCodes[(int)Keys.Right] = KeyCode.RightArrow;
keyCodes[(int)Keys.Left] = KeyCode.LeftArrow;
keyCodes[(int)Keys.Up] = KeyCode.UpArrow;
keyCodes[(int)Keys.Jump] = keyCodes[(int)Keys.Up];
keyCodes[(int)Keys.Down] = KeyCode.DownArrow;
keyCodes[(int)Keys.Dash] = KeyCode.RightControl;
keyCodes[(int)Keys.Shoot] = KeyCode.RightShift;
break;
public void init(int playerNumber)
{
this.playerNumber = playerNumber;
default:
Debug.LogError ("No keys defined for player number " + playerNumber);
break;
}
switch (playerNumber)
{
case 1:
keyCodes[(int)Keys.Right] = KeyCode.D;
keyCodes[(int)Keys.Left] = KeyCode.A;
keyCodes[(int)Keys.Up] = KeyCode.W;
keyCodes[(int)Keys.Jump] = keyCodes[(int)Keys.Up];
keyCodes[(int)Keys.Down] = KeyCode.S;
keyCodes[(int)Keys.Dash] = KeyCode.Space;
keyCodes[(int)Keys.Shoot] = KeyCode.LeftShift;
break;
case 2:
keyCodes[(int)Keys.Right] = KeyCode.RightArrow;
keyCodes[(int)Keys.Left] = KeyCode.LeftArrow;
keyCodes[(int)Keys.Up] = KeyCode.UpArrow;
keyCodes[(int)Keys.Jump] = keyCodes[(int)Keys.Up];
keyCodes[(int)Keys.Down] = KeyCode.DownArrow;
keyCodes[(int)Keys.Dash] = KeyCode.RightControl;
keyCodes[(int)Keys.Shoot] = KeyCode.RightShift;
break;
default:
Debug.LogError ("No keys defined for player number " + playerNumber);
break;
}
}
void OnCollisionEnter2D(Collision2D coll)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment