summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Exit.cs17
-rw-r--r--Assets/Scripts/Exit.cs.meta11
-rw-r--r--Assets/Scripts/MouseLook.cs10
-rw-r--r--Assets/Scripts/PlayerMovement.cs51
-rw-r--r--Assets/Scripts/PlayerMovement.cs.meta11
5 files changed, 99 insertions, 1 deletions
diff --git a/Assets/Scripts/Exit.cs b/Assets/Scripts/Exit.cs
new file mode 100644
index 0000000..a0feb04
--- /dev/null
+++ b/Assets/Scripts/Exit.cs
@@ -0,0 +1,17 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Exit : MonoBehaviour
+{
+ // Update is called once per frame
+ void Update()
+ {
+ if (Input.GetKey("escape"))
+ {
+ Debug.Log("Game is now closed.");
+ Application.Quit();
+ }
+
+ }
+}
diff --git a/Assets/Scripts/Exit.cs.meta b/Assets/Scripts/Exit.cs.meta
new file mode 100644
index 0000000..87fc2df
--- /dev/null
+++ b/Assets/Scripts/Exit.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3aa4285199d3f6f3a88d2b5993d8adfd
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/MouseLook.cs b/Assets/Scripts/MouseLook.cs
index f52f685..3365145 100644
--- a/Assets/Scripts/MouseLook.cs
+++ b/Assets/Scripts/MouseLook.cs
@@ -6,11 +6,13 @@ public class MouseLook : MonoBehaviour
public float mouseSensitivity = 100f;
public Transform playerBody;
+
+ float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
-
+ Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
@@ -18,6 +20,12 @@ public class MouseLook : MonoBehaviour
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
+
+ xRotation -= mouseY;
+
+ xRotation = Mathf.Clamp(xRotation, -90f, 90f);
+
+ transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs
new file mode 100644
index 0000000..b0b6874
--- /dev/null
+++ b/Assets/Scripts/PlayerMovement.cs
@@ -0,0 +1,51 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class PlayerMovement : MonoBehaviour
+{
+ public CharacterController controller;
+
+ public float speed = 12f;
+
+ public float gravity = -9.81f;
+
+ public float jumpHeight = 3f;
+
+ public Transform groundCheck;
+
+ public float groundDistance = 0.4f;
+
+ public LayerMask groundMask;
+
+ Vector3 velocity;
+ bool isGrounded;
+
+ // Update is called once per frame
+ void Update()
+ {
+ isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
+
+ if (isGrounded && velocity.y < 0)
+ {
+ velocity.y = -2f;
+ }
+
+ float x = Input.GetAxis("Horizontal");
+ float z = Input.GetAxis("Vertical");
+
+ Vector3 move = transform.right * x + transform.forward * z;
+
+ controller.Move(move * speed * Time.deltaTime);
+
+ if (Input.GetButtonDown("Jump") && isGrounded)
+ {
+ velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
+ }
+
+ velocity.y += gravity * Time.deltaTime;
+
+ controller.Move(velocity * Time.deltaTime);
+
+ }
+}
diff --git a/Assets/Scripts/PlayerMovement.cs.meta b/Assets/Scripts/PlayerMovement.cs.meta
new file mode 100644
index 0000000..7cb0f4d
--- /dev/null
+++ b/Assets/Scripts/PlayerMovement.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 0230ac989e3d56e25a60a15a70f53fd4
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: