Basic game completed
This commit is contained in:
31
3D FPS/Assets/Scripts/Player/PlayerCamMovement.cs
Normal file
31
3D FPS/Assets/Scripts/Player/PlayerCamMovement.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerCamMovement : MonoBehaviour
|
||||
{
|
||||
public float mouseSensitivity = 100f;
|
||||
public Transform playerBody;
|
||||
|
||||
private float xRotation = 0f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
11
3D FPS/Assets/Scripts/Player/PlayerCamMovement.cs.meta
Normal file
11
3D FPS/Assets/Scripts/Player/PlayerCamMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 398b178b957c88645b7e675a38f9fcf8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
3D FPS/Assets/Scripts/Player/PlayerHealth.cs
Normal file
46
3D FPS/Assets/Scripts/Player/PlayerHealth.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UI;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class PlayerHealth : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float startingHealth;
|
||||
private float health;
|
||||
public TextMeshProUGUI healthMonitor;
|
||||
public GameOverScreen gameOverScreen;
|
||||
private int score = 0;
|
||||
|
||||
public float Health
|
||||
{
|
||||
get
|
||||
{
|
||||
return health;
|
||||
}
|
||||
set
|
||||
{
|
||||
health = value;
|
||||
healthMonitor.text = "Health: " + health;
|
||||
if(health <= 0f)
|
||||
{
|
||||
playerDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
Health = startingHealth;
|
||||
}
|
||||
|
||||
private void playerDestroy()
|
||||
{
|
||||
gameOverScreen.TriggerScreen(score);
|
||||
}
|
||||
|
||||
public void AddScore(int n)
|
||||
{
|
||||
score += n;
|
||||
}
|
||||
}
|
||||
11
3D FPS/Assets/Scripts/Player/PlayerHealth.cs.meta
Normal file
11
3D FPS/Assets/Scripts/Player/PlayerHealth.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 479c0ccaabee4134cbe1aa7729b8ef75
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
3D FPS/Assets/Scripts/Player/PlayerMovement.cs
Normal file
53
3D FPS/Assets/Scripts/Player/PlayerMovement.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
public CharacterController charControl;
|
||||
|
||||
public float speed = 12f;
|
||||
public float gravity = -9.81f;
|
||||
public float jumpHeight = 3f;
|
||||
|
||||
|
||||
public Transform groundCheck;
|
||||
public float groundDistance = 0.4f;
|
||||
public LayerMask groundMask;
|
||||
|
||||
private Vector3 velocity;
|
||||
private bool isGrounded;
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
|
||||
if(isGrounded && velocity.y < 0)
|
||||
{
|
||||
velocity.y = -2f;
|
||||
}
|
||||
|
||||
float x = Input.GetAxis("Horizontal");
|
||||
float y = Input.GetAxis("Vertical");
|
||||
|
||||
Vector3 move = transform.right * x + transform.forward * y;
|
||||
|
||||
charControl.Move(move * speed * Time.deltaTime);
|
||||
|
||||
if(Input.GetButtonDown("Jump") && isGrounded)
|
||||
{
|
||||
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||
}
|
||||
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
|
||||
charControl.Move(velocity * Time.deltaTime);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
3D FPS/Assets/Scripts/Player/PlayerMovement.cs.meta
Normal file
11
3D FPS/Assets/Scripts/Player/PlayerMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 410f055c05365814bb67e15b9edf1824
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user