-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserInput.cs
56 lines (45 loc) · 1.12 KB
/
UserInput.cs
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
using UnityEngine;
using System.Collections;
public class UserInput : MonoBehaviour {
public bool walkByDefault = false;
private CharacterMovement charMove;
private Transform cam;
private Vector3 camForward;
private Vector3 move;
void Start(){
if (Camera.main != null) {
cam = Camera.main.transform;
}
charMove = GetComponent<CharacterMovement> ();
}
void FixedUpdate(){
float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis ("Vertical");
if (cam != null) {
camForward = Vector3.Scale (cam.forward, new Vector3 (1, 0, 1)).normalized;
move = vertical * camForward + horizontal * cam.right;
} else {
move = vertical * Vector3.forward + horizontal * Vector3.right;
}
if (move.magnitude > 1) {
move.Normalize ();
}
bool walkToggle = Input.GetKey (KeyCode.LeftShift);
float walkMultiplier = 1;
if (walkByDefault) {
if (walkToggle) {
walkMultiplier = 1;
} else {
walkMultiplier = 0.5f;
}
} else {
if (walkToggle) {
walkMultiplier = 1;
} else {
walkMultiplier = 0.5f;
}
}
move *= walkMultiplier;
charMove.Move (move);
}
}