add: Player script with hp
add: player death handling and OnLevelFailed event
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EyeEnemy : Enemy
|
||||
{
|
||||
public float _hp = 100;
|
||||
|
||||
void Start() {
|
||||
hp = _hp;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48cddee1e4d4837418957a7b4e6315c8
|
||||
@@ -4,8 +4,7 @@ using UnityEngine.SceneManagement;
|
||||
public class DeployController : MonoBehaviour
|
||||
{
|
||||
public void Start() {
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
GameController.SetCursorState(true);
|
||||
}
|
||||
|
||||
public void Deploy(string sceneName) {
|
||||
|
||||
@@ -3,11 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class GameController : MonoBehaviour
|
||||
{
|
||||
public static GameController i;
|
||||
public SceneAsset deployScene;
|
||||
public List<LevelInfo> levels;
|
||||
public List<EnemyInfo> enemies;
|
||||
|
||||
@@ -47,6 +49,10 @@ public class GameController : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public void OnLevelFailed(string sceneName, float timeSpent) {
|
||||
|
||||
}
|
||||
|
||||
EnemyInfo SelectEnemyWeighted() {
|
||||
float sumWeights = enemies.Sum(enemy => enemy.weight);
|
||||
float r = Random.Range(0, sumWeights);
|
||||
@@ -57,6 +63,15 @@ public class GameController : MonoBehaviour
|
||||
}
|
||||
return enemies[^1];
|
||||
}
|
||||
|
||||
public void LoadDeployScene() {
|
||||
SceneManager.LoadScene(deployScene.name);
|
||||
}
|
||||
|
||||
public static void SetCursorState(bool locked) {
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class LevelController : MonoBehaviour
|
||||
{
|
||||
public SceneAsset deployScene;
|
||||
public List<SpawnPointInfo> spawnPoints;
|
||||
|
||||
List<Enemy> aliveEnemies;
|
||||
@@ -33,10 +31,15 @@ public class LevelController : MonoBehaviour
|
||||
public void Update() {
|
||||
if (aliveEnemies.All(enemy => enemy == null)) {
|
||||
GameController.i.OnLevelClear(SceneManager.GetActiveScene().name, timeSpent);
|
||||
SceneManager.LoadScene(deployScene.name);
|
||||
GameController.i.LoadDeployScene();
|
||||
}
|
||||
timeSpent += Time.deltaTime;
|
||||
}
|
||||
|
||||
public void OnPlayerDie() {
|
||||
GameController.i.OnLevelFailed(SceneManager.GetActiveScene().name, timeSpent);
|
||||
GameController.i.LoadDeployScene();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -12,8 +12,7 @@ public class CameraMovement : MonoBehaviour
|
||||
|
||||
void Start() {
|
||||
cam = GetComponentInChildren<Camera>();
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
GameController.SetCursorState(true);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
public float maxHp = 100;
|
||||
|
||||
[SerializeField] float hp;
|
||||
|
||||
void Start() {
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
public void DealDamage(float damage) {
|
||||
hp -= damage;
|
||||
if (hp <= 0) {
|
||||
FindAnyObjectByType<LevelController>().OnPlayerDie();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9b2638aeb16f76429ff062f38f6d0be
|
||||
Reference in New Issue
Block a user