Commit f2431858 by Philipp Adolf

Move player initialization into new method

parent 6f542fd8
...@@ -61,32 +61,39 @@ public class PlayerControl : MonoBehaviour ...@@ -61,32 +61,39 @@ public class PlayerControl : MonoBehaviour
{ {
body2D = GetComponent<Rigidbody2D>(); body2D = GetComponent<Rigidbody2D>();
switch (playerNumber) init(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: public void init(int playerNumber)
keyCodes[(int)Keys.Right] = KeyCode.RightArrow; {
keyCodes[(int)Keys.Left] = KeyCode.LeftArrow; this.playerNumber = playerNumber;
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: switch (playerNumber)
Debug.LogError ("No keys defined for player number " + playerNumber); {
break; 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) 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