Skip to content

Commit 6513ef3

Browse files
committed
Added player GUI and jumping
1 parent 82abc95 commit 6513ef3

34 files changed

+247
-34
lines changed

Assembly-CSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Compile Include="Assets\Main Menu\Scripts\Options.cs" />
5050
<Compile Include="Assets\Player\MouseLook.cs" />
5151
<Compile Include="Assets\Player\PlayerController.cs" />
52+
<Compile Include="Assets\Player\PlayerGUI.cs" />
5253
<None Include="Assets\Standard Assets\CrossPlatformInput\CrossPlatformInputGuidelines.txt" />
5354
<Reference Include="UnityEngine.UI">
5455
<HintPath>C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>

Assets/Concept Art.meta

Lines changed: 0 additions & 9 deletions
This file was deleted.

Assets/Logo.png

854 Bytes
Loading

Assets/Logo.png.meta

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.

Assets/Player/MouseLook.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,30 @@ public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
1616
Quaternion originalRotation;
1717
void Update ()
1818
{
19-
if (axes == RotationAxes.MouseXAndY)
20-
{
21-
// Read the mouse input axis
22-
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
23-
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
24-
rotationX = ClampAngle (rotationX, minimumX, maximumX);
25-
rotationY = ClampAngle (rotationY, minimumY, maximumY);
26-
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
27-
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right);
28-
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
29-
}
30-
else if (axes == RotationAxes.MouseX)
31-
{
32-
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
33-
rotationX = ClampAngle (rotationX, minimumX, maximumX);
34-
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
35-
transform.localRotation = originalRotation * xQuaternion;
36-
}
37-
else
38-
{
39-
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
40-
rotationY = ClampAngle (rotationY, minimumY, maximumY);
41-
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.right);
42-
transform.localRotation = originalRotation * yQuaternion;
19+
if (Time.timeScale != 0) {
20+
if (axes == RotationAxes.MouseXAndY) {
21+
// Read the mouse input axis
22+
rotationX += Input.GetAxis ("Mouse X") * sensitivityX;
23+
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
24+
rotationX = ClampAngle (rotationX, minimumX, maximumX);
25+
rotationY = ClampAngle (rotationY, minimumY, maximumY);
26+
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
27+
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right);
28+
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
29+
} else if (axes == RotationAxes.MouseX) {
30+
rotationX += Input.GetAxis ("Mouse X") * sensitivityX;
31+
rotationX = ClampAngle (rotationX, minimumX, maximumX);
32+
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
33+
transform.localRotation = originalRotation * xQuaternion;
34+
} else {
35+
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
36+
rotationY = ClampAngle (rotationY, minimumY, maximumY);
37+
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.right);
38+
transform.localRotation = originalRotation * yQuaternion;
39+
}
4340
}
4441
}
42+
4543
void Start ()
4644
{
4745
// Make the rigid body not change rotation

Assets/Player/PlayerController.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,41 @@ public class PlayerController : MonoBehaviour {
55

66
public float speed;
77
private Rigidbody rb;
8+
9+
private bool isJumping = false;
10+
public float jumpSpeed = 0.3f;
11+
private double currJump = 0;
12+
public double allowedJump = 1;
13+
float distToGround;
14+
private bool isGrounded;
15+
816
// Use this for initialization
917
void Start () {
18+
19+
distToGround = GetComponent<Collider>().bounds.extents.y;
20+
1021
rb = GetComponent<Rigidbody> ();
1122
}
1223

1324
// Update is called once per frame
1425
void Update () {
15-
26+
27+
isGrounded = Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f);
28+
29+
if (isGrounded)
30+
currJump = 0;
31+
32+
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
33+
{
34+
isJumping = true;
35+
36+
Jump();
37+
}
38+
39+
if (isJumping && !isGrounded)
40+
{
41+
Jump();
42+
}
1643
}
1744

1845
// Called before every physics calculation
@@ -22,5 +49,23 @@ void FixedUpdate() {
2249

2350
Vector3 force = new Vector3 (-moveHorizontal, 0.0f, -moveVertical);
2451
rb.transform.Translate (force * speed);
52+
53+
}
54+
55+
public void Jump()
56+
{
57+
58+
if (currJump < allowedJump)
59+
{
60+
float temp = 0.0f;
61+
temp = Mathf.Sin(Time.deltaTime) * jumpSpeed;
62+
currJump += temp;
63+
rb.velocity = (Vector3.up * temp * jumpSpeed);
64+
}
65+
else
66+
{
67+
isJumping = false;
68+
}
2569
}
70+
2671
}

Assets/Player/PlayerGUI.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using UnityEngine.SceneManagement;
4+
5+
public class PlayerGUI : MonoBehaviour {
6+
7+
private bool isPause = false;
8+
public SpriteRenderer crosshair;
9+
public CanvasGroup pauseMenu;
10+
11+
// Use this for initialization
12+
void Start () {
13+
crosshair = crosshair.GetComponent<SpriteRenderer> ();
14+
pauseMenu = pauseMenu.GetComponent<CanvasGroup> ();
15+
16+
crosshair.enabled = true;
17+
pauseMenu.alpha = 0f;
18+
}
19+
20+
// Update is called once per frame
21+
void Update () {
22+
if(Input.GetKeyDown(KeyCode.Escape)) {
23+
isPause = !isPause;
24+
if (isPause) {
25+
Time.timeScale = 0;
26+
crosshair.enabled = false;
27+
pauseMenu.alpha = 1f;
28+
Cursor.visible = true;
29+
Cursor.lockState = CursorLockMode.None;
30+
31+
} else {
32+
Time.timeScale = 1;
33+
crosshair.enabled = true;
34+
pauseMenu.alpha = 0f;
35+
Cursor.visible = false;
36+
Cursor.lockState = CursorLockMode.Locked;
37+
}
38+
}
39+
}
40+
41+
public void Quit () {
42+
SceneManager.LoadScene (0);
43+
}
44+
}

Assets/Player/PlayerGUI.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)