Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dyingIsMainstream
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gamejam-gpn15
dyingIsMainstream
Commits
840d7973
Commit
840d7973
authored
Jun 04, 2015
by
Tim Reiter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for two players.
parent
903a70ed
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
PlayerControl.cs
Assets/Scripts/PlayerControl.cs
+27
-4
game.unity
Assets/game.unity
+0
-0
No files found.
Assets/Scripts/PlayerControl.cs
View file @
840d7973
...
@@ -24,11 +24,33 @@ public class PlayerControl : MonoBehaviour
...
@@ -24,11 +24,33 @@ public class PlayerControl : MonoBehaviour
[
HideInInspector
]
[
HideInInspector
]
public
Vector3
velocity
;
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
=
GetComponent
<
CharacterController2D
>();
_controller
.
onControllerCollidedEvent
+=
onControllerCollider
;
_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
...
@@ -51,7 +73,8 @@ public class PlayerControl : MonoBehaviour
if
(
_controller
.
isGrounded
)
if
(
_controller
.
isGrounded
)
velocity
.
y
=
0
;
velocity
.
y
=
0
;
if
(
Input
.
GetKey
(
KeyCode
.
RightArrow
))
if
(
Input
.
GetKey
(
goRightKeyCode
))
{
{
normalizedHorizontalSpeed
=
1
;
normalizedHorizontalSpeed
=
1
;
if
(
transform
.
localScale
.
x
<
0f
)
if
(
transform
.
localScale
.
x
<
0f
)
...
@@ -59,7 +82,7 @@ public class PlayerControl : MonoBehaviour
...
@@ -59,7 +82,7 @@ public class PlayerControl : MonoBehaviour
//if (_controller.isGrounded)
//if (_controller.isGrounded)
}
}
else
if
(
Input
.
GetKey
(
KeyCode
.
LeftArrow
))
else
if
(
Input
.
GetKey
(
goLeftKeyCode
))
{
{
normalizedHorizontalSpeed
=
-
1
;
normalizedHorizontalSpeed
=
-
1
;
if
(
transform
.
localScale
.
x
>
0f
)
if
(
transform
.
localScale
.
x
>
0f
)
...
@@ -75,7 +98,7 @@ public class PlayerControl : MonoBehaviour
...
@@ -75,7 +98,7 @@ public class PlayerControl : MonoBehaviour
}
}
if
(
Input
.
GetKeyDown
(
KeyCode
.
UpArrow
))
if
(
Input
.
GetKeyDown
(
jumpKeyCode
))
{
{
//to avoid DOUBLE JUMP
//to avoid DOUBLE JUMP
if
(
_controller
.
isGrounded
)
if
(
_controller
.
isGrounded
)
...
...
Assets/game.unity
View file @
840d7973
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment