Commit 840d7973 by Tim Reiter

added support for two players.

parent 903a70ed
......@@ -24,11 +24,33 @@ public class PlayerControl : MonoBehaviour
[HideInInspector]
public Vector3 velocity;
public int playerNumber = 1; //gibt an, ob es sich um player one, player two, etc. handelt. sollte nicht 0 sein;
KeyCode goRightKeyCode, goLeftKeyCode, jumpKeyCode;
void Awake()
void Start()
{
_controller = GetComponent<CharacterController2D>();
_controller.onControllerCollidedEvent += onControllerCollider;
switch (playerNumber)
{
case 1:
setKeyCodes(KeyCode.D,KeyCode.A,KeyCode.W);
break;
case 2:
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow);
break;
//TODO player 3 and 4
default:
break;
}
}
private void setKeyCodes(KeyCode right, KeyCode left, KeyCode up)
{
goRightKeyCode = right;
goLeftKeyCode = left;
jumpKeyCode = up;
}
......@@ -51,7 +73,8 @@ public class PlayerControl : MonoBehaviour
if (_controller.isGrounded)
velocity.y = 0;
if (Input.GetKey(KeyCode.RightArrow))
if (Input.GetKey(goRightKeyCode))
{
normalizedHorizontalSpeed = 1;
if (transform.localScale.x < 0f)
......@@ -59,7 +82,7 @@ public class PlayerControl : MonoBehaviour
//if (_controller.isGrounded)
}
else if (Input.GetKey(KeyCode.LeftArrow))
else if (Input.GetKey(goLeftKeyCode))
{
normalizedHorizontalSpeed = -1;
if (transform.localScale.x > 0f)
......@@ -75,7 +98,7 @@ public class PlayerControl : MonoBehaviour
}
if (Input.GetKeyDown(KeyCode.UpArrow))
if (Input.GetKeyDown(jumpKeyCode))
{
//to avoid DOUBLE JUMP
if (_controller.isGrounded)
......
No preview for this file type
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