Вы находитесь на странице: 1из 4

...olio\WaterDome\WaterDome\Assets\Scripts\MovementBetter.

cs 1
1 using UnityEngine;
2 using System.Collections;
3
4
5 public class MovementBetter : MonoBehaviour {
6
7 // for resetting camera position once headset is taken off
8 public bool isPaused = false;
9
10 public
UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController
mouse;
11 public float moveSpeed = 7.5f;
12 public float turnSpeed = 0.5f;
13 private Quaternion rotation_temp;
14 private bool flagged=true;
15 public float joystick_turn_sensitivity = 1.5f;
16 public float keyboardMoveMagnification = 50f;
17
18 //public Camera firstPersonCamera;
19 //public Camera domeCamera;
20
21
22 void Start()
23 {
24 mouse =
GetComponent<UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstP
ersonController>();
25 }
26
27
28
29 void LateUpdate()
30 {
31
32 // resets player position to center based upon pause status
33 if (isPaused)
34 {
35 transform.position = Vector3.zero;
36 }
37
38 // forgot why i do this?
39 if (Mathf.Abs(Input.GetAxis("LeftJoystickHorizontal")) > .2f || Mathf.Abs
(Input.GetAxis("LeftJoystickVertical")) > .2f)
40 {
41 mouse.enabled = false;
42 transform.GetChild(0).transform.rotation = Quaternion.Euler(0,
transform.rotation.eulerAngles.y, 0);
43 flagged = false;
...olio\WaterDome\WaterDome\Assets\Scripts\MovementBetter.cs 2
44 }
45 else
46 {
47 mouse.enabled = true;
48 }
49
50 if (Mathf.Abs(Input.GetAxis("RightJoystickHorizontal")) > .2f ||
Mathf.Abs(Input.GetAxis("RightJoystickVertical")) > .2f)
51 {
52 mouse.enabled = false;
53 transform.GetChild(0).transform.rotation = Quaternion.Euler(0,
transform.rotation.eulerAngles.y, 0);
54 flagged = false;
55
56 }
57 else
58 mouse.enabled = true;
59
60 if (mouse.enabled && !flagged)
61 {
62 mouse.mouseLook.Init(transform, transform.GetChild(0).transform);
63 if (transform.GetChild(0).transform.rotation.eulerAngles.x != 0)
64 flagged = true;
65 }
66
67 // Keyboard Inputs for Movement
68 if (Input.GetKey(KeyCode.W))
69 transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime *
keyboardMoveMagnification);
70
71 if (Input.GetKey(KeyCode.S))
72 transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime *
keyboardMoveMagnification);
73
74 if (Input.GetKey(KeyCode.Q) || Input.GetButton("BButton"))
75 transform.Translate(Vector3.up * moveSpeed * Time.deltaTime *
keyboardMoveMagnification);
76
77 if (Input.GetKey(KeyCode.E) || Input.GetButton("AButton"))
78 transform.Translate(Vector3.down * moveSpeed * Time.deltaTime *
keyboardMoveMagnification);
79
80 if (Input.GetKey(KeyCode.A))
81 transform.Translate(Vector3.left * moveSpeed * Time.deltaTime *
keyboardMoveMagnification);
82
83 if (Input.GetKey(KeyCode.D))
84 transform.Translate(Vector3.right * moveSpeed * Time.deltaTime *
keyboardMoveMagnification);
...olio\WaterDome\WaterDome\Assets\Scripts\MovementBetter.cs 3
85
86
87 // Xbox and Oculus Touch Controller Movements
88 if (Mathf.Abs(Input.GetAxis("LeftJoystickVertical")) > .2f)
89 transform.Translate(Vector3.forward * moveSpeed * Input.GetAxis
("LeftJoystickVertical"));
90 // Debug.Log("inputs: " + Input.GetAxis("LeftJoystickVertical") + " other
input: " + Input.GetAxis("LeftJoystickHorizontal") + " Names: "+
Input.GetJoystickNames()[0] + " Configured? " +
Input.IsJoystickPreconfigured(Input.GetJoystickNames()[0]));
91
92 // xbox left joystick controller movement
93 if (Mathf.Abs(Input.GetAxis("LeftJoystickHorizontal")) > .2f)
94 transform.rotation = Quaternion.Euler(0, Input.GetAxis
("LeftJoystickHorizontal") * joystick_turn_sensitivity +
transform.rotation.eulerAngles.y, 0);
95
96 // right Touch Controller Rotation
97 if (Mathf.Abs(Input.GetAxis("RightJoystickHorizontal")) > .2f)
98 transform.rotation = Quaternion.Euler(0, Input.GetAxis
("RightJoystickHorizontal") * joystick_turn_sensitivity +
transform.rotation.eulerAngles.y, 0);
99
100 // xbox right joystick controller movement
101 if (Mathf.Abs(Input.GetAxis("RightJoystickVertical")) > .2f)
102 transform.Translate(-Vector3.up * moveSpeed * Input.GetAxis
("RightJoystickVertical") / 5);
103 // Debug.Log("inputs: " + Input.GetAxis("RightJoystickVertical") + "
other input: " + Input.GetAxis("RightJoystickHorizontal") + " Names: "+
Input.GetJoystickNames()[0] + " Configured? " +
Input.IsJoystickPreconfigured(Input.GetJoystickNames()[0]));
104
105 // Returns back to center if pressed
106 if (Input.GetButton("XButton") || Input.GetKey(KeyCode.X))
107 transform.position = Vector3.zero;
108
109 // Inputs for quitting application
110 if (Input.GetButton("YButton") || Input.GetKey(KeyCode.Escape))
111 Application.Quit();
112
113
114
115
116 }
117
118 // argument for when headset has doesn't have focus - it pauses
119 public void OnApplicationFocus(bool hasfocus)
120 {
121 isPaused = !hasfocus;
...olio\WaterDome\WaterDome\Assets\Scripts\MovementBetter.cs 4
122 }
123
124 // argument for when the game engine has pause status to actually pause the
game
125 public void OnApplicationPause(bool pauseStatus)
126 {
127 isPaused = pauseStatus;
128 }
129
130 //// toggles camera to dome camera
131 //public void showDomeView()
132 //{
133 // firstPersonCamera.enabled = false;
134 // domeCamera.enabled = true;
135 //}
136
137
138 }
139

Вам также может понравиться