forked from Bollesyy/DonkeyKong
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerController
More file actions
67 lines (46 loc) · 1.11 KB
/
PlayerController
File metadata and controls
67 lines (46 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public enum PlatformerStates{grounded, climbing, airborne}
public PlatformerStates playerState;
public float maxSpeed = .5f;
public float jumpTakeOffSpeed = 7f;
public bool onLadder;
void Start ()
{
}
void Update ()
{
if (onLadder && Input.GetKey("w")) {
playerState = PlatformerStates.climbing;
MoveUp ();
}
if (onLadder && Input.GetKey("s")) {
MoveDown ();
}
if (!onLadder) {
playerState = PlatformerStates.grounded;
} if (Input.GetKey ("a") && playerState == PlatformerStates.grounded) {
MoveLeft ();
} if (Input.GetKey ("d") && playerState == PlatformerStates.grounded) {
MoveRight ();
}
}
public void MoveRight()
{
transform.position += new Vector3 (maxSpeed, 0, 0);
}
public void MoveLeft()
{
transform.position += new Vector3 (-maxSpeed, 0, 0);
}
public void MoveUp()
{
transform.position += new Vector3 (0, maxSpeed, 0);
}
public void MoveDown()
{
transform.position += new Vector3 (0, -maxSpeed, 0);
}
}