add: Player script with hp
add: player death handling and OnLevelFailed event
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user