-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class Billboard : MonoBehaviour | ||
{ | ||
public Transform cam; | ||
|
||
void LateUpdate() | ||
{ | ||
transform.LookAt(transform.position + cam.forward); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class Enemy : MonoBehaviour | ||
{ | ||
public Animator animator; | ||
public int maxHealth = 100; | ||
int currentHealth; | ||
|
||
public HealthBar healthBar; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
currentHealth = maxHealth; | ||
healthBar.SetMaxHealth(maxHealth); | ||
} | ||
|
||
public void TakeDamage(int damage) | ||
{ | ||
currentHealth -= damage; | ||
animator.SetTrigger("Hurt"); | ||
healthBar.SetHealth(currentHealth); | ||
|
||
if (currentHealth <= 0) | ||
{ | ||
Die(); | ||
} | ||
} | ||
|
||
void Die() | ||
{ | ||
animator.SetTrigger("IsDead"); | ||
|
||
GetComponent<Collider>().enabled = false; | ||
this.enabled = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class HealthBar : MonoBehaviour | ||
{ | ||
|
||
public Slider slider; | ||
public Gradient gradient; | ||
public Image fill; | ||
|
||
public void SetMaxHealth(int health) | ||
{ | ||
slider.maxValue = health; | ||
slider.value = health; | ||
|
||
fill.color = gradient.Evaluate(1f); | ||
} | ||
|
||
public void SetHealth(int health) | ||
{ | ||
slider.value = health; | ||
|
||
fill.color = gradient.Evaluate(slider.normalizedValue); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
public class MainMenu : MonoBehaviour | ||
{ | ||
public void PlayGame() | ||
{ | ||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); | ||
} | ||
|
||
public void QuitGame() | ||
{ | ||
Application.Quit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
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 | ||
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, 40f); | ||
|
||
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); | ||
playerBody.Rotate(Vector3.up * mouseX); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class Player : MonoBehaviour | ||
{ | ||
|
||
public int maxHealth = 100; | ||
public int currentHealth; | ||
|
||
public HealthBar healthBar; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
currentHealth = maxHealth; | ||
healthBar.SetMaxHealth(maxHealth); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Space)) | ||
{ | ||
TakeDamage(20); | ||
} | ||
} | ||
|
||
void TakeDamage(int damage) | ||
{ | ||
currentHealth -= damage; | ||
|
||
healthBar.SetHealth(currentHealth); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class PlayerCombat : MonoBehaviour | ||
{ | ||
public Animator animator; | ||
public Transform attackPoint; | ||
public float attackRange = 0.5f; | ||
public LayerMask enemyLayers; | ||
public int attackDamage = 40; | ||
|
||
public float attackRate = 2f; | ||
float nextAttackTime = 0f; | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (Time.time >= nextAttackTime) | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Q)) | ||
{ | ||
Attack(); | ||
nextAttackTime = Time.time + 1f / attackRate; | ||
} | ||
} | ||
} | ||
|
||
void Attack() | ||
{ | ||
animator.SetTrigger("Attack"); | ||
|
||
Collider[] hitEnemies = Physics.OverlapSphere(attackPoint.position, attackRange, enemyLayers); | ||
|
||
foreach (Collider enemy in hitEnemies) | ||
{ | ||
enemy.GetComponent<Enemy>().TakeDamage(attackDamage); | ||
} | ||
} | ||
|
||
void OnDrawGizmosSelected() | ||
{ | ||
if (attackPoint == null) | ||
{ | ||
return; | ||
} | ||
Gizmos.DrawWireSphere(attackPoint.position, attackRange); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class PlayerMovement : MonoBehaviour | ||
{ | ||
public CharacterController controller; | ||
public Animator animator; | ||
|
||
public float speed = 12f; | ||
public float gravity = -9.81f; | ||
|
||
public float jumpHeight = 3f; | ||
public Transform groundCheck; | ||
public float groundDistance = 0.4f; | ||
public LayerMask groundMask; | ||
|
||
public AudioClip footstepSound; | ||
public AudioClip jumpingSound; | ||
|
||
private AudioSource audioSource; | ||
|
||
Vector3 velocity; | ||
bool isGrounded; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
audioSource = GetComponent<AudioSource>(); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); | ||
|
||
if (isGrounded && velocity.y < 0) | ||
{ | ||
velocity.y = -2f; | ||
animator.SetBool("IsJumping", false); | ||
} | ||
|
||
float x = Input.GetAxis("Horizontal"); | ||
float z = Input.GetAxis("Vertical"); | ||
|
||
bool isMoving = Mathf.Abs(x) > 0.01f || Mathf.Abs(z) > 0.01f; | ||
if (isMoving) | ||
{ | ||
animator.SetBool("IsWalking", true); | ||
PlayFootstepSound(); | ||
} | ||
else | ||
{ | ||
animator.SetBool("IsWalking", false); | ||
animator.SetBool("IsIdle", true); | ||
audioSource.Stop(); | ||
} | ||
|
||
if (Input.anyKeyDown && (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A) | ||
|| Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.E))) | ||
{ | ||
animator.SetBool("IsWalking", true); | ||
PlayFootstepSound(); | ||
} | ||
|
||
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); | ||
animator.SetBool("IsJumping", true); | ||
audioSource.PlayOneShot(jumpingSound); | ||
} | ||
|
||
velocity.y += gravity * Time.deltaTime; | ||
controller.Move(velocity * Time.deltaTime); | ||
} | ||
|
||
private void PlayFootstepSound() | ||
{ | ||
if (!audioSource.isPlaying) | ||
{ | ||
audioSource.PlayOneShot(footstepSound); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
public class ResumeMenu : MonoBehaviour | ||
{ | ||
public static bool GameIsPaused = false; | ||
public GameObject pauseMenuUI; | ||
public GameObject stopMenuUI; | ||
HealthBar healthBar = new HealthBar(); | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (healthBar.slider.value <= 0) | ||
{ | ||
Stop(); | ||
} | ||
|
||
if (Input.GetKeyDown(KeyCode.Escape)) | ||
{ | ||
if (GameIsPaused) | ||
{ | ||
Resume(); | ||
} | ||
else | ||
{ | ||
Pause(); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
public void Resume() | ||
{ | ||
pauseMenuUI.SetActive(false); | ||
Time.timeScale = 1f; | ||
GameIsPaused = false; | ||
} | ||
|
||
public void Pause() | ||
{ | ||
pauseMenuUI.SetActive(true); | ||
Time.timeScale = 0f; | ||
GameIsPaused = true; | ||
} | ||
|
||
public void Stop() | ||
{ | ||
stopMenuUI.SetActive(true); | ||
Time.timeScale = 0f; | ||
GameIsPaused = true; | ||
} | ||
|
||
public void Quit() | ||
{ | ||
Application.Quit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class Rotator : MonoBehaviour | ||
{ | ||
public float speed = 50f; | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
transform.Rotate(0f, speed * Time.deltaTime, 0f); | ||
} | ||
} |
Oops, something went wrong.